dolos 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -0
- data/README.md +20 -8
- data/benchmarks/json/json.rb +31 -8
- data/benchmarks/json/nested_json_1m.json +20557 -0
- data/benchmarks/letter.rb +78 -0
- data/docs/.nojekyll +0 -0
- data/docs/README.md +22 -0
- data/docs/_sidebar.md +4 -0
- data/docs/getting_started.md +52 -0
- data/docs/index.html +26 -0
- data/examples/letter.rb +3 -3
- data/lib/dolos/common.rb +44 -0
- data/lib/dolos/parsers.rb +25 -16
- 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 +53 -45
- 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 +13 -5
- data/lib/dolos_common_parsers/common_parsers.rb +0 -34
- /data/benchmarks/json/{nested_json.json → nested_json_166.json} +0 -0
- /data/docs/{dolos_stable_diff.png → images/dolos_stable_diff.png} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 258d1d857ec1df4c70a50225e35114bbcc941b2901306d73db60543da1df93df
|
4
|
+
data.tar.gz: 3ec6f50215db6b4d719acc9552b5e6be34248452a7dcc4a6bef369e5e3c6ca2e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be62167ed5bd8b4bc57b5670434afc4b58789749f4306e70399416467160ba5f3a86a11adab7056d1b60ad72f96f3ed44e51fdc90601500a368e7ca7d99b7e19
|
7
|
+
data.tar.gz: 5e8f105222057ff27d9daafc2b2b5ec2e5e7b96ee7be84c665214b1d84e52fa0c87d126020a5606418b1a41002f69edbcbdf2d6bd514667c6b1317318c162373
|
data/.rubocop.yml
ADDED
data/README.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# Dolos
|
2
|
+
[![Gem version](https://badge.fury.io/rb/dolos.svg)](https://rubygems.org/gems/dolos)
|
3
|
+
[![Build status](https://github.com/benetis/dolos/actions/workflows/ruby.yml/badge.svg)](https://github.com/benetis/dolos/actions)
|
2
4
|
|
3
|
-
|
5
|
+
|
6
|
+
<img height="256" src="docs/images/dolos_stable_diff.png" width="256"/>
|
4
7
|
|
5
8
|
|
6
9
|
### Disclaimer
|
@@ -40,13 +43,13 @@ require 'dolos_common_parsers/common_parsers'
|
|
40
43
|
include Dolos
|
41
44
|
# frozen_string_literal: true
|
42
45
|
require_relative 'dolos'
|
43
|
-
require_relative '
|
46
|
+
require_relative 'dolos_parsers/common_parsers'
|
44
47
|
|
45
48
|
include Dolos
|
46
49
|
|
47
50
|
# Include common parsers
|
48
51
|
# In future this can be more structured, moved them to separate module to prevent breaking changes
|
49
|
-
include Dolos::
|
52
|
+
include Dolos::Common
|
50
53
|
|
51
54
|
# Library usage example
|
52
55
|
# Parse out a name and address from a letter
|
@@ -118,12 +121,21 @@ pp result.captures
|
|
118
121
|
### Benchmarks
|
119
122
|
`bundle exec ruby benchmarks/json/json.rb`
|
120
123
|
```
|
121
|
-
|
122
|
-
nested json benchmark
|
123
|
-
|
124
|
+
Dolos
|
125
|
+
nested json benchmark 8.426 (± 0.0%) i/s - 43.000 in 5.103600s
|
126
|
+
letter benchmark 3.145k (± 0.7%) i/s - 15.810k in 5.027961s
|
127
|
+
|
128
|
+
# Note: 23 times slower than Pure Ruby specialized json parser (below) if used to parse json
|
129
|
+
nested json 166KB bench 8.189 (± 0.0%) i/s - 41.000 in 5.007158s
|
130
|
+
nested json 1MB bench 0.959 (± 0.0%) i/s - 5.000 in 5.230650s
|
131
|
+
|
132
|
+
-----------------------------------------------------------
|
133
|
+
Pure ruby (flori/json)
|
134
|
+
nested json 1MB bench 24.213 (± 4.1%) i/s - 122.000 in 5.042309s
|
135
|
+
nested json 166KB bench 188.070 (± 1.6%) i/s - 954.000 in 5.073788s
|
136
|
+
Ruby native (C)
|
137
|
+
nested json 1MB bench 309.519 (± 0.3%) i/s - 1.560k in 5.040164s
|
124
138
|
```
|
125
|
-
Its very slow, not ready for use yet. API is unstable is as well.
|
126
|
-
|
127
139
|
|
128
140
|
### Contributing
|
129
141
|
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
|