dolos 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -5
- data/benchmarks/json/json.rb +31 -8
- data/benchmarks/json/nested_json_1m.json +20557 -0
- data/benchmarks/letter.rb +78 -0
- data/examples/letter.rb +2 -2
- data/lib/dolos/parsers.rb +13 -15
- data/lib/dolos/result.rb +12 -3
- data/lib/dolos/string_io_wrapper.rb +3 -8
- data/lib/dolos/version.rb +1 -1
- data/lib/dolos.rb +13 -39
- data/lib/dolos_common_parsers/common_parsers.rb +4 -0
- data/sig/dolos/common_parsers.rbs +11 -0
- data/sig/dolos/parser.rbs +6 -2
- data/sig/dolos/parser_state.rbs +1 -1
- data/sig/dolos/parsers.rbs +4 -0
- data/sig/dolos/result.rbs +7 -0
- metadata +5 -3
- /data/benchmarks/json/{nested_json.json → nested_json_166.json} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cfeffbbe4108e43ba81ccd210f2689910d310fc3947fe05ed22a9972e581e96a
|
4
|
+
data.tar.gz: e181ccca4725008464fc92670b8120cf55262ba469d6ec494270081eb902c241
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27fe73f34d41692d31c00d30bc03869cdefcef4ee785acbb72da12c9bceb85b78357da7c3d6d1435598b40fb635fb5e71d56254c18597c8d7d424748afc7c098
|
7
|
+
data.tar.gz: 9dd78f5e313830742505bbeb1488ed643a700facc2193ed3e996eef795913a50bb660a2af2dcd7c9a73e6e5f84befa7e461b2cf10d4bd11f22d68901ecc59e9b
|
data/README.md
CHANGED
@@ -118,12 +118,21 @@ pp result.captures
|
|
118
118
|
### Benchmarks
|
119
119
|
`bundle exec ruby benchmarks/json/json.rb`
|
120
120
|
```
|
121
|
-
|
122
|
-
nested json benchmark
|
123
|
-
|
121
|
+
Dolos
|
122
|
+
nested json benchmark 8.426 (± 0.0%) i/s - 43.000 in 5.103600s
|
123
|
+
letter benchmark 3.145k (± 0.7%) i/s - 15.810k in 5.027961s
|
124
|
+
|
125
|
+
# Note: 23 times slower than Pure Ruby specialized json parser (below) if used to parse json
|
126
|
+
nested json 166KB bench 8.189 (± 0.0%) i/s - 41.000 in 5.007158s
|
127
|
+
nested json 1MB bench 0.959 (± 0.0%) i/s - 5.000 in 5.230650s
|
128
|
+
|
129
|
+
-----------------------------------------------------------
|
130
|
+
Pure ruby (flori/json)
|
131
|
+
nested json 1MB bench 24.213 (± 4.1%) i/s - 122.000 in 5.042309s
|
132
|
+
nested json 166KB bench 188.070 (± 1.6%) i/s - 954.000 in 5.073788s
|
133
|
+
Ruby native (C)
|
134
|
+
nested json 1MB bench 309.519 (± 0.3%) i/s - 1.560k in 5.040164s
|
124
135
|
```
|
125
|
-
Its very slow, not ready for use yet. API is unstable is as well.
|
126
|
-
|
127
136
|
|
128
137
|
### Contributing
|
129
138
|
Contributors are welcome. Note: since library is not yet stable, I recommend getting in touch with me before starting to work on something.
|
data/benchmarks/json/json.rb
CHANGED
@@ -1,14 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'benchmark/ips'
|
4
|
+
require 'bundler/setup'
|
4
5
|
require 'dolos'
|
5
6
|
require 'dolos_common_parsers/common_parsers'
|
6
7
|
|
7
8
|
include Dolos
|
8
9
|
include Dolos::CommonParsers
|
9
|
-
|
10
|
-
def ws_rep0 = ws.rep0
|
11
|
-
|
12
10
|
def comma = c(",")
|
13
11
|
|
14
12
|
def string_literal = (c("\"") >> char_while(->(ch) { ch != "\"" }).opt << c("\""))
|
@@ -47,14 +45,39 @@ end
|
|
47
45
|
|
48
46
|
def json_parser = ws_rep0 >> value
|
49
47
|
|
50
|
-
|
48
|
+
require 'json/pure'
|
51
49
|
|
52
|
-
Benchmark.ips do |x|
|
53
|
-
x.time = 60
|
54
|
-
x.warmup = 15
|
55
50
|
|
56
|
-
|
51
|
+
json_from_file = File.read('benchmarks/json/nested_json_166.json')
|
52
|
+
|
53
|
+
result = json_parser.run(json_from_file)
|
54
|
+
puts result.success?
|
55
|
+
|
56
|
+
Benchmark.ips do |x|
|
57
|
+
x.report('nested json 166kb benchmark') do
|
57
58
|
json_parser.run(json_from_file)
|
58
59
|
end
|
60
|
+
x.report('Pure ruby json: nested json 166kb benchmark') do
|
61
|
+
JSON.parse(json_from_file)
|
62
|
+
end
|
63
|
+
x.compare!
|
64
|
+
end
|
65
|
+
|
66
|
+
json_from_file1m = File.read('benchmarks/json/nested_json_1m.json')
|
67
|
+
result1m = json_parser.run(json_from_file1m)
|
68
|
+
puts result1m.success?
|
69
|
+
|
70
|
+
# require 'json'
|
71
|
+
|
72
|
+
Benchmark.ips do |x|
|
73
|
+
# x.report('nested json 1mb benchmark') do
|
74
|
+
# json_parser.run(json_from_file1m)
|
75
|
+
# end
|
76
|
+
# x.report('Ruby native: nested json 1mb benchmark') do
|
77
|
+
# JSON.parse(json_from_file1m)
|
78
|
+
# end
|
79
|
+
# x.report('Pure ruby json: nested json 1mb benchmark') do
|
80
|
+
# JSON.parse(json_from_file1m)
|
81
|
+
# end
|
59
82
|
x.compare!
|
60
83
|
end
|