From cde514733d2c0c3c070d2452c653cf3a4eea0313 Mon Sep 17 00:00:00 2001 From: Drahflow Date: Thu, 10 Jan 2013 19:34:47 +0100 Subject: Some code clean- and speedup --- interpreter/ElymasGlobal.pm | 45 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) (limited to 'interpreter') diff --git a/interpreter/ElymasGlobal.pm b/interpreter/ElymasGlobal.pm index 351826b..aace222 100644 --- a/interpreter/ElymasGlobal.pm +++ b/interpreter/ElymasGlobal.pm @@ -567,9 +567,15 @@ sub installGlobal2IntFunction { $global->{$name} = [sub { my ($data, $scope) = @_; - my $b = popInt($data); - my $a = popInt($data); - push @$data, [&$code($a, $b), 'int']; + my $b = pop @$data; + unless($b->[1] eq 'int' and $data->[-1]->[1] eq 'int') { + die "Not int-typed arguments: " . Dumper($data->[-1], $b); + } + $data->[-1] = [&$code($data->[-1]->[0], $b->[0]), 'int']; + +# my $b = popInt($data); +# my $a = popInt($data); +# push @$data, [&$code($a, $b), 'int']; }, ['func', $name, ['int', 'int'], ['int']], 'active']; } @@ -754,4 +760,37 @@ installGlobal2StrFunction('streq', sub { return [($_[0] eq $_[1])? 1: 0, 'int'] # x: Extended Precision -> # _9: to 9: Constant Functions -> { 9 neg } ... { 9 } +use Time::HiRes qw(time); + +my %timings; + +sub takeTimings { + my ($scope) = @_; + + foreach my $key (keys %$scope) { + next if not ref($scope->{$key}->[1]); + + if($scope->{$key}->[1]->[0] eq 'func') { + my $sub = $scope->{$key}->[0]; + my $name = $scope->{$key}->[1]->[1]; + + $scope->{$key}->[0] = sub { + my $start = time; + &$sub(@_); + $timings{$name} += time - $start; + } + } elsif($scope->{$key}->[1]->[0] eq 'struct') { + takeTimings($scope->{$key}->[0]); + } + } +} + +# takeTimings($global); + +END { + foreach my $key (sort { $timings{$a} <=> $timings{$b} } keys %timings) { + printf "%s: %.6f\n", $key, $timings{$key}; + } +} + 1; -- cgit v1.2.3