fast_toml 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Cargo.lock +100 -5
- data/Rakefile +13 -9
- data/ext/fast_toml/Cargo.toml +3 -2
- data/ext/fast_toml/extconf.rb +3 -3
- data/ext/fast_toml/src/lib.rs +75 -8
- data/lib/fast_toml/version.rb +1 -1
- data/lib/fast_toml.rb +3 -2
- data/rakelib/benchmark.rake +53 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 616692a1fefe1c2178c4d4ba29db13c4c2b3484166ae3475310db498add0203b
|
4
|
+
data.tar.gz: a725e8b5df519f2dc6fdfd77db3a237307759a20ddadf65026fa2114957a2a5b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7266287ffa1e96f18e6dfd05d18ecae87c7a02da9523a7987788e0febb1489fb82930eee85c0103ee2d30682cc477bbfcf57a684985b730c843dfc7f5a92e885
|
7
|
+
data.tar.gz: 8fcee57de56013d86de3ff09013eb43e0a2abea7b672a51252ee6d67f70517729409e85db6ec70a49b79fa3ffa2ffb1b16767184eecc44bbf87c65090300f120
|
data/Cargo.lock
CHANGED
@@ -54,9 +54,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
|
54
54
|
|
55
55
|
[[package]]
|
56
56
|
name = "clang-sys"
|
57
|
-
version = "1.
|
57
|
+
version = "1.8.1"
|
58
58
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
59
|
-
checksum = "
|
59
|
+
checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4"
|
60
60
|
dependencies = [
|
61
61
|
"glob",
|
62
62
|
"libc",
|
@@ -69,11 +69,18 @@ version = "1.12.0"
|
|
69
69
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
70
70
|
checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b"
|
71
71
|
|
72
|
+
[[package]]
|
73
|
+
name = "equivalent"
|
74
|
+
version = "1.0.1"
|
75
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
76
|
+
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
|
77
|
+
|
72
78
|
[[package]]
|
73
79
|
name = "fast_toml"
|
74
|
-
version = "0.
|
80
|
+
version = "0.2.0"
|
75
81
|
dependencies = [
|
76
82
|
"magnus",
|
83
|
+
"toml",
|
77
84
|
]
|
78
85
|
|
79
86
|
[[package]]
|
@@ -82,6 +89,22 @@ version = "0.3.1"
|
|
82
89
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
83
90
|
checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
|
84
91
|
|
92
|
+
[[package]]
|
93
|
+
name = "hashbrown"
|
94
|
+
version = "0.14.5"
|
95
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
96
|
+
checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
|
97
|
+
|
98
|
+
[[package]]
|
99
|
+
name = "indexmap"
|
100
|
+
version = "2.2.6"
|
101
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
102
|
+
checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26"
|
103
|
+
dependencies = [
|
104
|
+
"equivalent",
|
105
|
+
"hashbrown",
|
106
|
+
]
|
107
|
+
|
85
108
|
[[package]]
|
86
109
|
name = "itertools"
|
87
110
|
version = "0.12.1"
|
@@ -166,9 +189,9 @@ dependencies = [
|
|
166
189
|
|
167
190
|
[[package]]
|
168
191
|
name = "proc-macro2"
|
169
|
-
version = "1.0.
|
192
|
+
version = "1.0.85"
|
170
193
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
171
|
-
checksum = "
|
194
|
+
checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23"
|
172
195
|
dependencies = [
|
173
196
|
"unicode-ident",
|
174
197
|
]
|
@@ -253,6 +276,35 @@ version = "0.3.5"
|
|
253
276
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
254
277
|
checksum = "a3f0bf26fd526d2a95683cd0f87bf103b8539e2ca1ef48ce002d67aad59aa0b4"
|
255
278
|
|
279
|
+
[[package]]
|
280
|
+
name = "serde"
|
281
|
+
version = "1.0.203"
|
282
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
283
|
+
checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094"
|
284
|
+
dependencies = [
|
285
|
+
"serde_derive",
|
286
|
+
]
|
287
|
+
|
288
|
+
[[package]]
|
289
|
+
name = "serde_derive"
|
290
|
+
version = "1.0.203"
|
291
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
292
|
+
checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba"
|
293
|
+
dependencies = [
|
294
|
+
"proc-macro2",
|
295
|
+
"quote",
|
296
|
+
"syn",
|
297
|
+
]
|
298
|
+
|
299
|
+
[[package]]
|
300
|
+
name = "serde_spanned"
|
301
|
+
version = "0.6.6"
|
302
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
303
|
+
checksum = "79e674e01f999af37c49f70a6ede167a8a60b2503e56c5599532a65baa5969a0"
|
304
|
+
dependencies = [
|
305
|
+
"serde",
|
306
|
+
]
|
307
|
+
|
256
308
|
[[package]]
|
257
309
|
name = "shell-words"
|
258
310
|
version = "1.1.0"
|
@@ -276,6 +328,40 @@ dependencies = [
|
|
276
328
|
"unicode-ident",
|
277
329
|
]
|
278
330
|
|
331
|
+
[[package]]
|
332
|
+
name = "toml"
|
333
|
+
version = "0.8.13"
|
334
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
335
|
+
checksum = "a4e43f8cc456c9704c851ae29c67e17ef65d2c30017c17a9765b89c382dc8bba"
|
336
|
+
dependencies = [
|
337
|
+
"serde",
|
338
|
+
"serde_spanned",
|
339
|
+
"toml_datetime",
|
340
|
+
"toml_edit",
|
341
|
+
]
|
342
|
+
|
343
|
+
[[package]]
|
344
|
+
name = "toml_datetime"
|
345
|
+
version = "0.6.6"
|
346
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
347
|
+
checksum = "4badfd56924ae69bcc9039335b2e017639ce3f9b001c393c1b2d1ef846ce2cbf"
|
348
|
+
dependencies = [
|
349
|
+
"serde",
|
350
|
+
]
|
351
|
+
|
352
|
+
[[package]]
|
353
|
+
name = "toml_edit"
|
354
|
+
version = "0.22.13"
|
355
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
356
|
+
checksum = "c127785850e8c20836d49732ae6abfa47616e60bf9d9f57c43c250361a9db96c"
|
357
|
+
dependencies = [
|
358
|
+
"indexmap",
|
359
|
+
"serde",
|
360
|
+
"serde_spanned",
|
361
|
+
"toml_datetime",
|
362
|
+
"winnow",
|
363
|
+
]
|
364
|
+
|
279
365
|
[[package]]
|
280
366
|
name = "unicode-ident"
|
281
367
|
version = "1.0.12"
|
@@ -345,3 +431,12 @@ name = "windows_x86_64_msvc"
|
|
345
431
|
version = "0.52.5"
|
346
432
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
347
433
|
checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0"
|
434
|
+
|
435
|
+
[[package]]
|
436
|
+
name = "winnow"
|
437
|
+
version = "0.6.9"
|
438
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
439
|
+
checksum = "86c949fede1d13936a99f14fafd3e76fd642b556dd2ce96287fbe2e0151bfac6"
|
440
|
+
dependencies = [
|
441
|
+
"memchr",
|
442
|
+
]
|
data/Rakefile
CHANGED
@@ -1,19 +1,23 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
require
|
6
|
-
require
|
3
|
+
$LOAD_PATH.unshift File.expand_path(__dir__)
|
4
|
+
|
5
|
+
require 'bundler/gem_tasks'
|
6
|
+
require 'minitest/test_task'
|
7
|
+
require 'rubocop/rake_task'
|
8
|
+
require 'rb_sys/extensiontask'
|
9
|
+
require 'lib/fast_toml'
|
7
10
|
|
8
11
|
Minitest::TestTask.create
|
9
|
-
RuboCop::RakeTask.new
|
10
12
|
|
11
|
-
|
13
|
+
RuboCop::RakeTask.new
|
12
14
|
|
13
|
-
GEMSPEC = Gem::Specification.load(
|
15
|
+
GEMSPEC = Gem::Specification.load('fast_toml.gemspec')
|
14
16
|
|
15
|
-
RbSys::ExtensionTask.new(
|
16
|
-
ext.lib_dir =
|
17
|
+
RbSys::ExtensionTask.new('fast_toml', GEMSPEC) do |ext|
|
18
|
+
ext.lib_dir = 'lib/fast_toml'
|
17
19
|
end
|
18
20
|
|
21
|
+
task build: :compile
|
22
|
+
|
19
23
|
task default: %i[compile test rubocop]
|
data/ext/fast_toml/Cargo.toml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
[package]
|
2
2
|
name = "fast_toml"
|
3
|
-
version = "0.
|
3
|
+
version = "0.2.0"
|
4
4
|
edition = "2021"
|
5
5
|
authors = ["Guilherme Carreiro <karreiro@gmail.com>"]
|
6
6
|
license = "MIT"
|
@@ -10,4 +10,5 @@ publish = false
|
|
10
10
|
crate-type = ["cdylib"]
|
11
11
|
|
12
12
|
[dependencies]
|
13
|
-
magnus =
|
13
|
+
magnus = "0.6.4"
|
14
|
+
toml = "0.8.13"
|
data/ext/fast_toml/extconf.rb
CHANGED
data/ext/fast_toml/src/lib.rs
CHANGED
@@ -1,15 +1,82 @@
|
|
1
|
+
use magnus::exception::runtime_error;
|
1
2
|
use magnus::function;
|
2
3
|
use magnus::prelude::*;
|
3
|
-
use magnus::
|
4
|
-
use magnus::
|
5
|
-
|
6
|
-
fn hello(subject: String) -> String {
|
7
|
-
format!("Hello from Rust, {subject}!")
|
8
|
-
}
|
4
|
+
use magnus::value::{InnerValue, Lazy};
|
5
|
+
use magnus::RModule;
|
6
|
+
use magnus::{IntoValue, RArray, RHash, Ruby};
|
9
7
|
|
10
8
|
#[magnus::init]
|
11
|
-
fn init(ruby: &Ruby) -> Result<(), Error> {
|
9
|
+
fn init(ruby: &Ruby) -> Result<(), magnus::Error> {
|
12
10
|
let module = ruby.define_module("FastToml")?;
|
13
|
-
module.define_singleton_method("
|
11
|
+
module.define_singleton_method("parse", function!(parse, 1))?;
|
14
12
|
Ok(())
|
15
13
|
}
|
14
|
+
|
15
|
+
fn parse(str: String) -> Result<magnus::Value, magnus::Error> {
|
16
|
+
let toml_value = toml::from_str(&str);
|
17
|
+
|
18
|
+
match toml_value {
|
19
|
+
Ok(toml_value) => {
|
20
|
+
let ruby_value = to_ruby_value(toml_value);
|
21
|
+
Ok(ruby_value)
|
22
|
+
}
|
23
|
+
Err(err) => {
|
24
|
+
let ruby_err = to_ruby_err(err.message());
|
25
|
+
Err(ruby_err)
|
26
|
+
}
|
27
|
+
}
|
28
|
+
}
|
29
|
+
|
30
|
+
fn to_ruby_err(err_msg: &str) -> magnus::Error {
|
31
|
+
let ruby_api = Ruby::get();
|
32
|
+
|
33
|
+
if let Ok(ruby_api) = ruby_api {
|
34
|
+
let module = fast_toml_module(&ruby_api);
|
35
|
+
|
36
|
+
let err_class = module
|
37
|
+
.define_error("Error", ruby_api.exception_standard_error())
|
38
|
+
.expect("Failed to define or get FastToml::Error");
|
39
|
+
|
40
|
+
return magnus::Error::new(err_class, err_msg.to_string());
|
41
|
+
}
|
42
|
+
|
43
|
+
magnus::Error::new(runtime_error(), "FastToml runtime err")
|
44
|
+
}
|
45
|
+
|
46
|
+
fn fast_toml_module(ruby_api: &Ruby) -> RModule {
|
47
|
+
Lazy::new(|ruby| {
|
48
|
+
ruby.define_module("FastToml")
|
49
|
+
.expect("Failed to define or get FastToml")
|
50
|
+
})
|
51
|
+
.get_inner_with(ruby_api)
|
52
|
+
}
|
53
|
+
|
54
|
+
fn to_ruby_value(value: toml::Value) -> magnus::Value {
|
55
|
+
match value {
|
56
|
+
toml::Value::String(string) => string.into_value(),
|
57
|
+
toml::Value::Integer(integer) => integer.into_value(),
|
58
|
+
toml::Value::Float(float) => float.into_value(),
|
59
|
+
toml::Value::Boolean(boolean) => boolean.into_value(),
|
60
|
+
toml::Value::Datetime(date) => date.to_string().into_value(),
|
61
|
+
toml::Value::Array(rust_array) => {
|
62
|
+
let ruby_array = RArray::new();
|
63
|
+
|
64
|
+
for value in rust_array {
|
65
|
+
let value = to_ruby_value(value);
|
66
|
+
ruby_array.push(value).unwrap();
|
67
|
+
}
|
68
|
+
|
69
|
+
ruby_array.into_value()
|
70
|
+
}
|
71
|
+
toml::Value::Table(rust_map) => {
|
72
|
+
let ruby_hash = RHash::new();
|
73
|
+
|
74
|
+
for (key, value) in rust_map {
|
75
|
+
let value = to_ruby_value(value);
|
76
|
+
ruby_hash.aset(key, value).unwrap();
|
77
|
+
}
|
78
|
+
|
79
|
+
ruby_hash.into_value()
|
80
|
+
}
|
81
|
+
}
|
82
|
+
}
|
data/lib/fast_toml/version.rb
CHANGED
data/lib/fast_toml.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
4
|
-
require_relative
|
3
|
+
require_relative 'fast_toml/version'
|
4
|
+
require_relative 'fast_toml/fast_toml'
|
5
5
|
|
6
6
|
module FastToml
|
7
7
|
class Error < StandardError; end
|
8
|
+
# Your code goes here...
|
8
9
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'benchmark'
|
4
|
+
require 'benchmark/ips'
|
5
|
+
require 'toml'
|
6
|
+
require 'toml-rb'
|
7
|
+
require 'perfect_toml'
|
8
|
+
require 'tomlrb'
|
9
|
+
|
10
|
+
TOML_INPUT = <<~TOML
|
11
|
+
[package]
|
12
|
+
name = "fast_toml"
|
13
|
+
version = "0.1.0"
|
14
|
+
edition = "2021"
|
15
|
+
authors = ["Guilherme Carreiro <karreiro@gmail.com>"]
|
16
|
+
license = "MIT"
|
17
|
+
publish = false
|
18
|
+
|
19
|
+
[lib]
|
20
|
+
crate-type = ["cdylib"]
|
21
|
+
|
22
|
+
[dependencies]
|
23
|
+
magnus = "0.6.4"
|
24
|
+
toml = "0.8.13"
|
25
|
+
TOML
|
26
|
+
|
27
|
+
namespace :benchmark do
|
28
|
+
desc 'Benchmark different TOML parsers (ips)'
|
29
|
+
task :ips do
|
30
|
+
Benchmark.ips do |x|
|
31
|
+
x.report('fast_toml') { FastToml.parse(TOML_INPUT) }
|
32
|
+
x.report('toml') { TOML::Parser.new(TOML_INPUT).parsed }
|
33
|
+
x.report('toml-rb') { TomlRB.parse(TOML_INPUT) }
|
34
|
+
x.report('perfect_toml') { PerfectTOML.parse(TOML_INPUT) }
|
35
|
+
x.report('tomlrb') { Tomlrb.parse(TOML_INPUT) }
|
36
|
+
|
37
|
+
x.compare!
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
desc 'Benchmark different TOML parsers (ms)'
|
42
|
+
task :ms do
|
43
|
+
n = 5_000
|
44
|
+
|
45
|
+
Benchmark.bm(20) do |x|
|
46
|
+
x.report('fast_toml:') { n.times { FastToml.parse(TOML_INPUT) } }
|
47
|
+
x.report('toml:') { n.times { TOML::Parser.new(TOML_INPUT).parsed } }
|
48
|
+
x.report('toml-rb:') { n.times { TomlRB.parse(TOML_INPUT) } }
|
49
|
+
x.report('perfect_toml:') { n.times { PerfectTOML.parse(TOML_INPUT) } }
|
50
|
+
x.report('tomlrb:') { n.times { Tomlrb.parse(TOML_INPUT) } }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fast_toml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Guilherme Carreiro
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rb_sys
|
@@ -44,6 +44,7 @@ files:
|
|
44
44
|
- ext/fast_toml/src/lib.rs
|
45
45
|
- lib/fast_toml.rb
|
46
46
|
- lib/fast_toml/version.rb
|
47
|
+
- rakelib/benchmark.rake
|
47
48
|
homepage: https://github.com/karreiro/fast_toml
|
48
49
|
licenses:
|
49
50
|
- MIT
|