in reply to Benchmarking "Are all these characters in this sentence?"
I tried a little modified version of the RMGir_index one and the results are ... random. Especially since you do a lot more work in the benchmark than just the test you want to compare, the results depend on too many things and the actual different code seems to play only small part of it. I think you should at least change the benchmark_routine() to something like
to give a little more weight to the tested subroutine. Not that it helped too much in this case.sub benchmark_routine { my ($testFn, $testName)=@_; foreach(@testCases) { my ($sentence, $wantedLetters, $expectedResult) = @$_; $testFn->($sentence, $wantedLetters) for (1..20); die "$testName test failed ($sentence, $wantedLetters)" unless (($testFn->($sentence, $wantedLetters))==$expectedRes +ult); } }
sub RMGir_indexNot { my ($sentence, $wantedLetters)=@_; # don't need this variable (or any of them, in # fact -- they're just here for clarity. # we could work straight out of @_ if we wanted # this terser # Also, the $[ check is just pedantic - if someone # changes $[, shoot them. return !(grep index($sentence,$_)<$[, split //,$wantedLetters); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Benchmarking "Are all these characters in this sentence?"
by RMGir (Prior) on Aug 29, 2008 at 09:58 UTC |