From ab3d458b72bebf36d27685643c02c80be53b0c75 Mon Sep 17 00:00:00 2001 From: John Regehr Date: Fri, 6 May 2011 17:25:30 -0600 Subject: [PATCH] Add a cache to avoid re-testing programs that come up multiple times, some legitimately and some due to a bit of sloppiness in the matching strategies. --- utah/scripts/custom_delta.pl | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/utah/scripts/custom_delta.pl b/utah/scripts/custom_delta.pl index 9b48fed4d..902c2b3cd 100755 --- a/utah/scripts/custom_delta.pl +++ b/utah/scripts/custom_delta.pl @@ -3,6 +3,8 @@ use strict; # todo: cache results! or at least a hash of results +# can clear cache every time program gets smaller +# but enforce this policy # todo: input file should print output separately instead of checksum # probably do this via command line option? @@ -394,6 +396,9 @@ ($) my %method_worked = (); my %method_failed = (); +my %cache = (); +my $cache_hits = 0; +my $old_size = 1000000000; sub main_loop ($$$) { (my $cfile, my $test, my $method) = @_; @@ -413,16 +418,36 @@ ($$$) print "no more to delete.\n"; return $worked; } - write_file ($cfile); - if (run_test ($test)) { + my $hit = 0; + my $result = $cache{$prog}; + if (defined($result)) { + $cache_hits++; + $hit = 1; + print "(hit) "; + } else { + write_file ($cfile); + $result = run_test ($test); + $cache{$prog} = $result; + } + + if ($result) { print "success\n"; + die if ($hit); system "cp $cfile $cfile.bak"; $good_cnt++; $worked = 1; $method_worked{$method}++; + my $size = length ($prog); + die if ($size > $old_size); + if ($size < $old_size) { + %cache = (); + } + $old_size = $size; } else { print "failure\n"; - system "cp $cfile.bak $cfile"; + if (!$hit) { + system "cp $cfile.bak $cfile"; + } if ($newpos <= $filepos) { $filepos++; } else { @@ -538,3 +563,4 @@ sub bymethod { $f=0 unless defined($f); print " method $method worked $w times and failed $f times\n"; } +print "there were $cache_hits cache hits\n";