File tree Expand file tree Collapse file tree 1 file changed +35
-1
lines changed Expand file tree Collapse file tree 1 file changed +35
-1
lines changed Original file line number Diff line number Diff line change 1- use criterion:: { criterion_group, criterion_main, BatchSize , Criterion } ;
21use std:: time:: Duration ;
32
3+ use criterion:: { criterion_group, criterion_main, BatchSize , Criterion } ;
4+
45use mlua:: prelude:: * ;
56
67fn collect_gc_twice ( lua : & Lua ) {
@@ -43,6 +44,38 @@ fn encode_json(c: &mut Criterion) {
4344 } ) ;
4445}
4546
47+ fn decode_json ( c : & mut Criterion ) {
48+ let lua = Lua :: new ( ) ;
49+
50+ let decode = lua
51+ . create_function ( |lua, s : String | {
52+ lua. to_value ( & serde_json:: from_str :: < serde_json:: Value > ( & s) . unwrap ( ) )
53+ } )
54+ . unwrap ( ) ;
55+ let json = r#"{
56+ "name": "Clark Kent",
57+ "address": {
58+ "city": "Smallville",
59+ "state": "Kansas",
60+ "country": "USA"
61+ },
62+ "age": 22,
63+ "parents": ["Jonathan Kent", "Martha Kent"],
64+ "superman": true,
65+ "interests": ["flying", "saving the world", "kryptonite"]
66+ }"# ;
67+
68+ c. bench_function ( "deserialize json" , |b| {
69+ b. iter_batched (
70+ || collect_gc_twice ( & lua) ,
71+ |_| {
72+ decode. call :: < _ , LuaTable > ( json) . unwrap ( ) ;
73+ } ,
74+ BatchSize :: SmallInput ,
75+ ) ;
76+ } ) ;
77+ }
78+
4679criterion_group ! {
4780 name = benches;
4881 config = Criterion :: default ( )
@@ -51,6 +84,7 @@ criterion_group! {
5184 . noise_threshold( 0.02 ) ;
5285 targets =
5386 encode_json,
87+ decode_json,
5488}
5589
5690criterion_main ! ( benches) ;
You can’t perform that action at this time.
0 commit comments