Subject: | PATCH: cmp_deeply() 6x speedup on large arrays of strings |
This patch speeds up cmp_deeply() on large data structures in which most
elements are non-references in both the got and expected structures.
For me it gives a factor of 6 speedup for cmp_deeply() on identical
arrays of 50_000 strings.t
Subject: | patch.txt |
diff -NrdU5 Test-Deep-0.106.orig/lib/Test/Deep.pm Test-Deep-0.106/lib/Test/Deep.pm
--- Test-Deep-0.106.orig/lib/Test/Deep.pm 2009-08-09 22:09:08.000000000 +0200
+++ Test-Deep-0.106/lib/Test/Deep.pm 2010-03-03 21:01:53.000000000 +0200
@@ -254,10 +254,23 @@
sub descend
{
my ($d1, $d2) = @_;
+ if (!ref $d1 and !ref $d2)
+ {
+ # Shortcut comparison for the non-reference case.
+ if (defined $d1)
+ {
+ return 1 if defined $d2 and $d1 eq $d2;
+ }
+ else
+ {
+ return 1 if !defined $d2;
+ }
+ }
+
if (! $Expects and ref($d1) and UNIVERSAL::isa($d1, "Test::Deep::Cmp"))
{
my $where = $Stack->render('$data');
confess "Found a special comparison in $where\nYou can only the specials in the expects structure";
}