forked from rurban/smhasher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfixupdocspeeds.pl
executable file
·70 lines (67 loc) · 1.61 KB
/
fixupdocspeeds.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/perl
use strict;
use File::Copy 'mv';
my $endtest = qr(^(?:---|\[\[\[|Input vcode 0x));
if (@ARGV) {
readf($_) for @ARGV;
} else {
readf("log.speed");
}
sub readf {
my $fn = shift;
my ($n,$speed,$hash);
open(my $l, "<", $fn) or die "open $fn $!";
while (<$l>) {
if (/^--- Testing ([\w-_]+) \"/) {
if ($n) { # fixup previous name
fixup($n,$speed,$hash,$fn) if $hash or $speed;
}
$n = $1; $speed = $hash = undef;
} elsif (/^\[\[\[ 'Hashmap' Speed/) {
while (<$l>) {
last if $_ =~ $endtest;
$hash .= $_;
}
} elsif (/^\[\[\[ Speed Tests/) {
while (<$l>) {
last if $_ =~ $endtest;
$speed .= $_;
}
} elsif (/^\[\[\[ /) {
last;
}
}
fixup($n,$speed,$hash,$fn) if $n; # fixup last name
}
sub fixup {
my ($n,$speed,$hash,$fn) = @_;
return unless $n;
return if !defined($speed) && !defined($hash);
return if "doc/$n.txt" eq $fn;
open(my $I, "<", "doc/$n.txt") or die "open doc/$n.txt $!";
open(my $O, ">", "doc/$n.new") or die "open doc/$n.new $!";
my $found;
while (<$I>) {
print $O $_;
# search for $n in doc
if (/^--- Testing /) {
$found = /^--- Testing $n /;
}
elsif ($found && defined $hash && /^\[\[\[ 'Hashmap' Speed/) {
print $O $hash;
while (<$I>) {
last if $_ =~ $endtest;
}
print $O $_;
} elsif ($found && defined $speed && /^\[\[\[ Speed Tests/) {
print $O $speed;
while (<$I>) {
last if $_ =~ $endtest;
}
print $O $_;
}
}
close $I;
close $O;
mv ("doc/$n.new", "doc/$n.txt") if $found;
}