ccsv 1.0.1 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of ccsv might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/CHANGELOG +6 -0
- data/Gemfile +6 -4
- data/Gemfile.lock +5 -4
- data/Manifest +2 -0
- data/ccsv.gemspec +4 -13
- data/ext/ccsv.c +6 -6
- data/spec/bench_spec.rb +43 -0
- data/spec/ccsv_spec.rb +17 -82
- metadata +9 -10
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 34b2006a8c527845d151e267d0bc5e090c4e0d64
|
4
|
+
data.tar.gz: 8ad5846879c62e79df4b37048077d76eb8103f87
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2461629af33ea91ff00625ed09e41088a77bab31b16634feb9d39b16bf54b155145a764c3b144b62d757145e6b8b1e494ada3bd2abb288ac2014ae472b79c1fd
|
7
|
+
data.tar.gz: 40efd6635ef75d093f0138a874a044f1769a0f4d395ce79664988b484eb0ad6d06d3fb1c3f905d6c10954f4b7c191a958e64e9cea53471d02c30945d9202a008
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
v1.0.4 Range methods min/max replaced by first/last for stable work (zhum)
|
2
|
+
|
3
|
+
v1.0.3 Benchmarks now in spec-style (zhum).
|
4
|
+
|
5
|
+
v1.0.2 Benchmarks added (zhum).
|
6
|
+
|
1
7
|
v1.0.1 Tests moved to minitest (zhum).
|
2
8
|
|
3
9
|
v1.0.0 Allow custom delimiter and integer range filtration (zhum).
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
GEM
|
2
|
+
remote: https://rubygems.org/
|
2
3
|
specs:
|
3
4
|
allison (2.0.3)
|
4
|
-
echoe (4.6.
|
5
|
+
echoe (4.6.6)
|
5
6
|
allison (>= 2.0.3)
|
6
7
|
rake (>= 0.9.2)
|
7
8
|
rdoc (>= 2.5.11)
|
8
9
|
rubyforge (>= 2.0.4)
|
9
10
|
json (1.8.1)
|
10
11
|
json_pure (1.8.1)
|
11
|
-
minitest (5.
|
12
|
-
rake (10.
|
13
|
-
rdoc (4.
|
12
|
+
minitest (5.3.4)
|
13
|
+
rake (10.3.2)
|
14
|
+
rdoc (4.1.1)
|
14
15
|
json (~> 1.4)
|
15
16
|
rubyforge (2.0.4)
|
16
17
|
json_pure (>= 1.1.7)
|
data/Manifest
CHANGED
data/ccsv.gemspec
CHANGED
@@ -2,29 +2,20 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "ccsv"
|
5
|
-
s.version = "1.0.
|
5
|
+
s.version = "1.0.4"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Evan Weaver, Sergey Zhumatiy"]
|
9
|
-
s.date = "2014-
|
9
|
+
s.date = "2014-05-26"
|
10
10
|
s.description = "Ruby CSV parser gem, written in pure C."
|
11
11
|
s.email = "serg@parallel.ru"
|
12
12
|
s.extensions = ["ext/extconf.rb"]
|
13
13
|
s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README.rdoc", "ext/ccsv.c", "ext/ccsv.h", "ext/extconf.rb"]
|
14
|
-
s.files = ["CHANGELOG", "Gemfile", "Gemfile.lock", "LICENSE", "Manifest", "README.rdoc", "Rakefile", "compile", "ext/ccsv.c", "ext/ccsv.h", "ext/extconf.rb", "spec/
|
14
|
+
s.files = ["CHANGELOG", "Gemfile", "Gemfile.lock", "LICENSE", "Manifest", "README.rdoc", "Rakefile", "ccsv.gemspec", "compile", "ext/ccsv.c", "ext/ccsv.h", "ext/extconf.rb", "spec/bench_spec.rb", "spec/ccsv_spec.rb"]
|
15
15
|
s.homepage = "http://github.com/evan/ccsv/"
|
16
16
|
s.rdoc_options = ["--line-numbers", "--title", "Ccsv", "--main", "README.rdoc"]
|
17
17
|
s.require_paths = ["lib", "ext"]
|
18
18
|
s.rubyforge_project = "evan"
|
19
|
-
s.rubygems_version = "
|
19
|
+
s.rubygems_version = "2.0.14"
|
20
20
|
s.summary = "A pure-C CSV parser."
|
21
|
-
|
22
|
-
if s.respond_to? :specification_version then
|
23
|
-
s.specification_version = 3
|
24
|
-
|
25
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
26
|
-
else
|
27
|
-
end
|
28
|
-
else
|
29
|
-
end
|
30
21
|
end
|
data/ext/ccsv.c
CHANGED
@@ -56,12 +56,12 @@ static VALUE foreach(int argc, VALUE* argv, VALUE self) {
|
|
56
56
|
searchfield=-1;
|
57
57
|
}
|
58
58
|
|
59
|
-
|
60
|
-
array_length=NUM2INT(
|
59
|
+
array_length_method=rb_funcall(rest_args,rb_intern("length"), 0);
|
60
|
+
array_length=NUM2INT(array_length_method);
|
61
61
|
/*rb_warn("Length=%d",array_length);*/
|
62
62
|
|
63
|
-
min_method = rb_intern("
|
64
|
-
max_method = rb_intern("
|
63
|
+
min_method = rb_intern("first");
|
64
|
+
max_method = rb_intern("last");
|
65
65
|
/*------------test_id = rb_intern("class");*/
|
66
66
|
range_i=0;
|
67
67
|
for(idx=2;idx<array_length;++idx){
|
@@ -82,7 +82,7 @@ static VALUE foreach(int argc, VALUE* argv, VALUE self) {
|
|
82
82
|
|
83
83
|
min_val=rb_funcall(e, min_method, 0);
|
84
84
|
max_val=rb_funcall(e, max_method, 0);
|
85
|
-
|
85
|
+
/*rb_warn("!\n");*/
|
86
86
|
pairs[range_i].low=NUM2LONG(min_val);
|
87
87
|
/*rb_warn("2\n");*/
|
88
88
|
pairs[range_i].high=NUM2LONG(max_val);
|
@@ -102,7 +102,7 @@ static VALUE foreach(int argc, VALUE* argv, VALUE self) {
|
|
102
102
|
start=line;
|
103
103
|
nobackslash=line;
|
104
104
|
while(token=index(nobackslash, DELIM)){
|
105
|
-
/*
|
105
|
+
/*rb_warning("5\n");*/
|
106
106
|
count=0;
|
107
107
|
t2=token-1;
|
108
108
|
while((t2>=line) && (*t2=='\\'))
|
data/spec/bench_spec.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler.require(:default, :test)
|
3
|
+
|
4
|
+
require 'minitest/autorun'
|
5
|
+
require 'minitest/benchmark'
|
6
|
+
require 'ccsv'
|
7
|
+
require 'csv'
|
8
|
+
|
9
|
+
TEST_CSV_FILES={
|
10
|
+
100=>"/tmp/test1.csv",
|
11
|
+
10000=>"/tmp/test2.csv",
|
12
|
+
100000=>"/tmp/test3.csv"
|
13
|
+
}
|
14
|
+
|
15
|
+
def create_csvf(name,limit)
|
16
|
+
open(name,"w") do |f|
|
17
|
+
1.upto(limit) do |n|
|
18
|
+
f.puts [n,2*n,3+n].join(',')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "Ccsv Benchmark" do
|
24
|
+
bench_range { [100,10_000,100_000] }
|
25
|
+
before do
|
26
|
+
[100,10_000,100_000].each do |n|
|
27
|
+
create_csvf(TEST_CSV_FILES[n],n)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
after do
|
32
|
+
[100,10_000,100_000].each do |n|
|
33
|
+
FileUtils.rm TEST_CSV_FILES[n]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
bench_performance_linear "Ccsv", 0.8 do |n|
|
38
|
+
Ccsv.foreach(TEST_CSV_FILES[n]) do |x| end
|
39
|
+
end
|
40
|
+
bench_performance_linear "CSV", 0.8 do |n|
|
41
|
+
CSV.foreach(TEST_CSV_FILES[n]) do |x| end
|
42
|
+
end
|
43
|
+
end
|
data/spec/ccsv_spec.rb
CHANGED
@@ -1,26 +1,16 @@
|
|
1
1
|
require 'bundler'
|
2
2
|
Bundler.require(:default, :test)
|
3
3
|
|
4
|
-
|
5
|
-
#require 'minitest/benchmark'
|
4
|
+
require 'minitest/spec'
|
6
5
|
require 'minitest/autorun'
|
7
|
-
#require 'minitest/spec'
|
8
6
|
require 'ccsv'
|
9
|
-
#require 'csv'
|
10
7
|
|
11
8
|
TEST_CSV="/tmp/test.csv"
|
9
|
+
DEF_SIZE=20000
|
12
10
|
|
13
|
-
|
14
|
-
def self.foreach(file, &block)
|
15
|
-
open(file) do |f|
|
16
|
-
scan(f, &block)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def create_csv(delimiter=',')
|
11
|
+
def create_csv(delimiter=',',limit=DEF_SIZE)
|
22
12
|
open(TEST_CSV,"w") do |f|
|
23
|
-
1.upto(
|
13
|
+
1.upto(limit) do |n|
|
24
14
|
f.puts [n,2*n,3+n].join(delimiter)
|
25
15
|
end
|
26
16
|
end
|
@@ -32,13 +22,17 @@ describe Ccsv do
|
|
32
22
|
@csv=[]
|
33
23
|
end
|
34
24
|
|
25
|
+
after do
|
26
|
+
begin; FileUtils.rm TEST_CSV; rescue; end
|
27
|
+
end
|
28
|
+
|
35
29
|
it 'reads csv with default delimiter' do
|
36
30
|
create_csv
|
37
31
|
Ccsv.foreach(TEST_CSV) do |v|
|
38
32
|
@csv << v
|
39
33
|
end
|
40
34
|
@csv[15000].must_equal(['15001','30002','15004'])
|
41
|
-
@csv.size.must_equal(
|
35
|
+
@csv.size.must_equal(DEF_SIZE)
|
42
36
|
end
|
43
37
|
|
44
38
|
it 'reads csv with tab delimiter' do
|
@@ -63,72 +57,13 @@ describe Ccsv do
|
|
63
57
|
}.must_raise(RuntimeError)
|
64
58
|
end
|
65
59
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
end
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
__END__
|
76
|
-
require 'test/unit'
|
77
|
-
require 'ccsv'
|
78
|
-
require 'benchmark'
|
79
|
-
|
80
|
-
# Yeah, I know.
|
81
|
-
begin
|
82
|
-
require 'csv'
|
83
|
-
require 'rubygems'
|
84
|
-
require 'lightcsv'
|
85
|
-
require 'csvscan'
|
86
|
-
|
87
|
-
module CSVScan
|
88
|
-
def self.foreach(file, &block)
|
89
|
-
open(file) do |f|
|
90
|
-
scan(f, &block)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
rescue LoadError
|
96
|
-
end
|
97
|
-
|
98
|
-
class TestCcsv < Test::Unit::TestCase
|
99
|
-
|
100
|
-
def setup
|
101
|
-
@dir = "#{File.dirname(__FILE__)}/../"
|
102
|
-
end
|
103
|
-
|
104
|
-
def test_should_raise
|
105
|
-
assert_raises(RuntimeError) do
|
106
|
-
Ccsv.foreach('fdssfd') do
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
def test_accuracy
|
112
|
-
ccsv = []
|
113
|
-
file = @dir + "data_small.csv"
|
114
|
-
Ccsv.foreach(file) do |values|
|
115
|
-
ccsv << values.dup
|
116
|
-
end
|
117
|
-
csv = []
|
118
|
-
CSV.foreach(file) do |values|
|
119
|
-
csv << values
|
120
|
-
end
|
121
|
-
assert_equal csv, ccsv
|
122
|
-
end
|
123
|
-
|
124
|
-
def test_speed
|
125
|
-
Benchmark.bm(5) do |x|
|
126
|
-
[Ccsv, CSV].each do |klass| # CSVScan, LightCsv,
|
127
|
-
x.report(klass.name) do
|
128
|
-
klass.foreach(@dir + "data.csv") do |values| end
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
60
|
+
it 'filters csv' do
|
61
|
+
create_csv
|
62
|
+
Ccsv.foreach(TEST_CSV,',',0,[3000..4000]) do |v|
|
63
|
+
@csv << v
|
64
|
+
end
|
65
|
+
@csv[0].must_equal(['3001','6002','3004'])
|
66
|
+
@csv.size.must_equal(999)
|
67
|
+
end
|
133
68
|
|
134
69
|
end
|
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ccsv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.4
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Evan Weaver, Sergey Zhumatiy
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2014-
|
11
|
+
date: 2014-05-26 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
13
|
description: Ruby CSV parser gem, written in pure C.
|
15
14
|
email: serg@parallel.ru
|
@@ -31,14 +30,16 @@ files:
|
|
31
30
|
- Manifest
|
32
31
|
- README.rdoc
|
33
32
|
- Rakefile
|
33
|
+
- ccsv.gemspec
|
34
34
|
- compile
|
35
35
|
- ext/ccsv.c
|
36
36
|
- ext/ccsv.h
|
37
37
|
- ext/extconf.rb
|
38
|
+
- spec/bench_spec.rb
|
38
39
|
- spec/ccsv_spec.rb
|
39
|
-
- ccsv.gemspec
|
40
40
|
homepage: http://github.com/evan/ccsv/
|
41
41
|
licenses: []
|
42
|
+
metadata: {}
|
42
43
|
post_install_message:
|
43
44
|
rdoc_options:
|
44
45
|
- --line-numbers
|
@@ -50,21 +51,19 @@ require_paths:
|
|
50
51
|
- lib
|
51
52
|
- ext
|
52
53
|
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
-
none: false
|
54
54
|
requirements:
|
55
|
-
- -
|
55
|
+
- - '>='
|
56
56
|
- !ruby/object:Gem::Version
|
57
57
|
version: '0'
|
58
58
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
-
none: false
|
60
59
|
requirements:
|
61
|
-
- -
|
60
|
+
- - '>='
|
62
61
|
- !ruby/object:Gem::Version
|
63
62
|
version: '1.2'
|
64
63
|
requirements: []
|
65
64
|
rubyforge_project: evan
|
66
|
-
rubygems_version:
|
65
|
+
rubygems_version: 2.0.14
|
67
66
|
signing_key:
|
68
|
-
specification_version:
|
67
|
+
specification_version: 4
|
69
68
|
summary: A pure-C CSV parser.
|
70
69
|
test_files: []
|