@@ -9,8 +9,13 @@ extern crate stdweb;
9
9
#[ macro_use]
10
10
extern crate lazy_static;
11
11
12
+ #[ macro_use]
13
+ extern crate serde_derive;
14
+
12
15
use std:: time:: Duration ;
16
+ use std:: collections:: HashMap ;
13
17
18
+ use stdweb:: Reference ;
14
19
use stdweb:: web:: document;
15
20
use stdweb:: web:: event:: ClickEvent ;
16
21
use stdweb:: unstable:: TryInto ;
@@ -135,10 +140,61 @@ fn run_benchmarks< F: FnOnce( &mut Bencher ) >( callback: F ) {
135
140
}
136
141
}
137
142
143
+ #[ derive( PartialEq , Serialize , Deserialize , Debug ) ]
144
+ struct Struct {
145
+ number : i32 ,
146
+ boolean : bool ,
147
+ string : String ,
148
+ array : Vec < i32 > ,
149
+ object : HashMap < String , i32 >
150
+ }
151
+
152
+ js_serializable ! ( Struct ) ;
153
+
138
154
fn main ( ) {
139
155
run_benchmarks ( |bencher| {
140
156
bencher. add ( "call-into-js" , || || js ! ( @( no_return) ) ) ;
141
157
bencher. add ( "call-into-js-returning-undefined" , || || js ! ( ) ) ;
158
+ bencher. add ( "call-into-js-returning-bool" , || || js ! ( return true ; ) ) ;
159
+ bencher. add ( "call-into-js-returning-string" , || || js ! ( return "Hello world!" ; ) ) ;
142
160
bencher. add ( "call-into-js-with-string" , || || js ! ( @( no_return) var test = @{ "Hello world!" } ; ) ) ;
161
+ bencher. add ( "call-into-js-with-bool" , || || js ! ( @( no_return) var test = @{ true } ; ) ) ;
162
+ bencher. add ( "call-into-js-with-array" , || || js ! ( @( no_return) var test = @{ & [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ] [ ..] } ; ) ) ;
163
+ bencher. add ( "call-into-js-with-object" , || {
164
+ let object: HashMap < _ , _ > =
165
+ vec ! [
166
+ ( "One" . to_owned( ) , 1 ) ,
167
+ ( "Two" . to_owned( ) , 2 ) ,
168
+ ( "Three" . to_owned( ) , 3 )
169
+ ] . into_iter ( ) . collect ( ) ;
170
+
171
+ move || js ! ( @( no_return) var test = @{ & object} ; )
172
+ } ) ;
173
+ bencher. add ( "call-into-js-with-serde-struct" , || {
174
+ let structure = Struct {
175
+ number : 123 ,
176
+ boolean : true ,
177
+ string : "Hello world!" . to_owned ( ) ,
178
+ array : vec ! [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ] ,
179
+ object : vec ! [
180
+ ( "One" . to_owned( ) , 1 ) ,
181
+ ( "Two" . to_owned( ) , 2 ) ,
182
+ ( "Three" . to_owned( ) , 3 )
183
+ ] . into_iter ( ) . collect ( )
184
+ } ;
185
+
186
+ move || js ! ( @( no_return) var test = @{ & structure} ; )
187
+ } ) ;
188
+ bencher. add ( "call-into-js-with-reference" , || {
189
+ let reference: Reference = js ! ( return [ @{ 0 } ] ; ) . try_into ( ) . unwrap ( ) ;
190
+ move || js ! ( @( no_return) var test = @{ & reference} ; )
191
+ } ) ;
192
+ bencher. add ( "call-into-js-with-reference-while-having-a-lot-of-references" , || {
193
+ let references: Vec < Reference > = ( 0 ..1000 ) . into_iter ( ) . map ( |nth| {
194
+ js ! ( return [ @{ nth} ] ; ) . try_into ( ) . unwrap ( )
195
+ } ) . collect ( ) ;
196
+
197
+ move || js ! ( @( no_return) var test = @{ & references[ 0 ] } ; )
198
+ } ) ;
143
199
} ) ;
144
200
}
0 commit comments