File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -366,6 +366,39 @@ fn userdata_call_method(c: &mut Criterion) {
366
366
} ) ;
367
367
}
368
368
369
+ // A userdata method call that goes through an implicit `__index` function
370
+ fn userdata_call_method_complex ( c : & mut Criterion ) {
371
+ struct UserData ( u64 ) ;
372
+ impl LuaUserData for UserData {
373
+ fn register ( registry : & mut LuaUserDataRegistry < Self > ) {
374
+ registry. add_field_method_get ( "val" , |_, this| Ok ( this. 0 ) ) ;
375
+ registry. add_method_mut ( "inc_by" , |_, this, by : u64 | {
376
+ this. 0 += by;
377
+ Ok ( this. 0 )
378
+ } ) ;
379
+ }
380
+ }
381
+
382
+ let lua = Lua :: new ( ) ;
383
+ let ud = lua. create_userdata ( UserData ( 0 ) ) . unwrap ( ) ;
384
+ let inc_by = lua
385
+ . load ( "function(ud, s) return ud:inc_by(s) end" )
386
+ . eval :: < LuaFunction > ( )
387
+ . unwrap ( ) ;
388
+
389
+ c. bench_function ( "userdata [call method complex]" , |b| {
390
+ b. iter_batched (
391
+ || {
392
+ collect_gc_twice ( & lua) ;
393
+ } ,
394
+ |_| {
395
+ inc_by. call :: < ( ) > ( ( & ud, 1 ) ) . unwrap ( ) ;
396
+ } ,
397
+ BatchSize :: SmallInput ,
398
+ ) ;
399
+ } ) ;
400
+ }
401
+
369
402
fn userdata_async_call_method ( c : & mut Criterion ) {
370
403
struct UserData ( i64 ) ;
371
404
impl LuaUserData for UserData {
@@ -430,6 +463,7 @@ criterion_group! {
430
463
userdata_create,
431
464
userdata_call_index,
432
465
userdata_call_method,
466
+ userdata_call_method_complex,
433
467
userdata_async_call_method,
434
468
}
435
469
You can’t perform that action at this time.
0 commit comments