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 } ;
2
1
use std:: time:: Duration ;
3
2
3
+ use criterion:: { criterion_group, criterion_main, BatchSize , Criterion } ;
4
+
4
5
use mlua:: prelude:: * ;
5
6
6
7
fn collect_gc_twice ( lua : & Lua ) {
@@ -43,6 +44,38 @@ fn encode_json(c: &mut Criterion) {
43
44
} ) ;
44
45
}
45
46
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
+
46
79
criterion_group ! {
47
80
name = benches;
48
81
config = Criterion :: default ( )
@@ -51,6 +84,7 @@ criterion_group! {
51
84
. noise_threshold( 0.02 ) ;
52
85
targets =
53
86
encode_json,
87
+ decode_json,
54
88
}
55
89
56
90
criterion_main ! ( benches) ;
You can’t perform that action at this time.
0 commit comments