Skip to content

Commit 7d8be11

Browse files
committed
benchmark update
1 parent 410e406 commit 7d8be11

File tree

1 file changed

+74
-33
lines changed

1 file changed

+74
-33
lines changed

Dev/bench.pl

Lines changed: 74 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,68 +13,109 @@
1313

1414

1515

16-
{ ##settung global functions
16+
# { ##setting global functions
1717

18-
my $t = timeit($count, sub{
19-
$js->set('test', sub{});
20-
});
21-
print_results("set global functions", $t);
22-
}
18+
# my $t = timeit($count, sub{
19+
# $js->set('test', sub{});
20+
# });
21+
# print_results("set global functions", $t);
22+
# }
2323

24-
{ ##getting javascript object
24+
# { ##getting javascript object
2525

26-
my $t = timeit($count, sub{
27-
$duk->eval_string(qq~
28-
function javascriptObject1 (){}
29-
javascriptObject1;
30-
~);
26+
# my $t = timeit($count, sub{
27+
# $duk->eval_string(qq~
28+
# function javascriptObject1 (){}
29+
# javascriptObject1;
30+
# ~);
3131

32-
my $obj = $duk->to_perl_object(-1);
33-
$duk->pop();
34-
});
35-
print_results("getting objects", $t);
36-
}
32+
# my $obj = $duk->to_perl_object(-1);
33+
# $duk->pop();
34+
# });
35+
# print_results("getting objects", $t);
36+
# }
3737

3838
{ ##object operations
3939
$duk->eval_string(qq~
4040
function javascriptObject (){
41+
this.test = 9;
4142
this.callme = function(n){
4243
this.test = n;
4344
}
4445
}
46+
47+
javascriptObject.prototype.setfunc = function(fn){
48+
this.fn = fn;
49+
print(this.fn(9,8));
50+
};
51+
52+
javascriptObject.prototype.testcall = function(a,b){
53+
this.fn(a,9);
54+
return a+b;
55+
};
56+
4557
javascriptObject;
4658
~);
4759
my $obj = $duk->to_perl_object(-1);
4860
$duk->pop();
4961

50-
{ #calling new on objects
51-
my $t = timeit($count, sub{
52-
my $o = $obj->new();
53-
});
54-
print_results("calling new", $t);
55-
}
62+
# { #calling new on objects
63+
# my $t = timeit($count, sub{
64+
# my $o = $obj->new();
65+
# });
66+
# print_results("calling new", $t);
67+
# }
5668

57-
{ #calling function from objects
69+
# { #calling function from objects
70+
# my $o = $obj->new();
71+
# my $i = 0;
72+
# my $t = timeit($count, sub{
73+
# $o->callme($i++);
74+
# # print $o->test, "\n";
75+
# });
76+
# print_results("calling function", $t);
77+
# }
78+
79+
{ #setting functions
5880
my $o = $obj->new();
5981
my $i = 0;
82+
83+
$o->setfunc($duk->cache( sub {
84+
# print Dumper \@_;
85+
# print "cool\n";
86+
87+
# print "cool\n";
88+
return 88;
89+
}));
90+
6091
my $t = timeit($count, sub{
61-
$o->callme($i++);
62-
# print $o->test, "\n";
92+
# my $n = $o->fn($i++, 7);
93+
my $result = $o->testcall(1,3);
94+
# print $result, "\n";
6395
});
64-
print_results("calling function", $t);
96+
print_results("calling cached function", $t);
6597
}
6698
}
6799

100+
my @results;
101+
68102
sub print_results {
69103
my $name = shift;
70104
my $t = shift;
71105

72106
my @result = split('@', timestr($t));
73107

74-
print "===================================\n";
75-
print "$count $name\n";
76-
print "===================================\n";
77-
print " " . $result[0], "\n";
78-
print $result[1], "\n";
79-
print "\n\n";
108+
my $r = "";
109+
$r .= "===================================\n";
110+
$r .= "$count $name\n";
111+
$r .= "===================================\n";
112+
$r .= " " . $result[0] . "\n";
113+
$r .= $result[1] . "\n";
114+
$r .= "\n\n";
115+
116+
push @results, $r;
117+
}
118+
119+
for (@results){
120+
print $_;
80121
}

0 commit comments

Comments
 (0)