Skip to content

Commit

Permalink
TODO test the performance of growing the tmps stack
Browse files Browse the repository at this point in the history
  • Loading branch information
tonycoz committed Nov 27, 2023
1 parent 23e1e44 commit 55b0882
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions MANIFEST
Expand Up @@ -6448,6 +6448,7 @@ t/perf/opcount.t See if optimised subs have the right op counts
t/perf/optree.t Test presence of some op optimisations
t/perf/speed.t See if optimisations are keeping things fast
t/perf/taint.t See if optimisations are keeping things fast (taint issues)
t/perf/tmps.t Check that tmps stack grows in O(n)-ish time
t/perl.supp Perl valgrind suppressions
t/porting/args_assert.t Check that all PERL_ARGS_ASSERT* macros are used
t/porting/authors.t Check that all authors have been acknowledged
Expand Down
57 changes: 57 additions & 0 deletions t/perf/tmps.t
@@ -0,0 +1,57 @@
#!./perl

BEGIN {
chdir 't' if -d 't';
@INC = ('../lib');
require Config; Config->import;
require './test.pl';
skip_all_if_miniperl("No XS modules under miniperl");
}

use strict;
use warnings;

# test this many times to try to avoid noise from othe processes
my $trial_count = 3;

use List::Util qw(min);

my %basetimes;
# need around 1e6 for the O(n**2) behaviour to really kick in
my $small_size = 50_000;
my $large_size = 1_000_000;

for my $size ($small_size, $large_size) {
for my $j (1 .. $trial_count) {
my $time = fresh_perl(<<'CODE', { args => [ $size ] });
use strict;
use Time::HiRes qw(time);
my $size = shift;
my $s = (join " ", 0 .. 9) . "\n";
$s x= $size;
my @x;
my $start = time;
@x = $s =~ /(.*?\n|.+)/gs;
@x == $size or die;
print time() - $start;
CODE
is($?, 0, "size $size run $j success");
like($time, qr/^[\d.]+(?:e-?\d+)?\n?$/, "size $size run $j result valid");
chomp $time;
push $basetimes{$size}->@*, $time;
note "size $size run $j result $time";
}
}

my $min_small = min($basetimes{$small_size}->@*);
my $min_large = min($basetimes{$large_size}->@*);
my $ratio = $large_size / $small_size;

our $TODO = "tmps stack grows in O(n**2) time";
my $worst = $min_small * $ratio * 2;
note "worst allowed $worst";
cmp_ok($min_large, '<', $worst,
"check growing the tmps stack takes O(n) time");

done_testing();

0 comments on commit 55b0882

Please sign in to comment.