From: Dominic Dunlop Date: Tue, 25 Mar 1997 14:39:26 +0000 (+0100) Subject: Reduce memory footprint of complex.t X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d26eb0becc8c51ffd352f1667ada71b0e03e9b19;p=p5sagit%2Fp5-mst-13.2.git Reduce memory footprint of complex.t Over the weekend, I said: >Passes all expected tests on MachTen 4.0.3, EXCEPT... > >lib/complex fails to run because it wants more virtual memory than my >system can provide. My system can provide 22 megs, which is not vast, but >should be adequate to run a test, so I think lib/complex is being greedy. >I'm pretty sure that the cause is repeated use of .= or similar on a >scalar: the system malloc() which perl has to use on MachTen does not >appear to coalesce free()d chunks, so behaves very badly when a scalar >grows repeatedly. Anyway, I'll delve deeper and probably post a patch. Here's that patch. It saves 2,861 (give or take) of those realloc()s my system's native malloc() package fields so badly. Beware long lines. Hope they reach you unmangled. (If not, ask me to send it uuencoded, or as a MIME attachment or something.) You'll also need to hand patch a --ignore-whitespace option: tabs will have been munged into spaces. p5p-msgid: v03020902af5d8e03c5ab@[194.51.248.84] --- diff --git a/t/lib/complex.t b/t/lib/complex.t index 5dcac6c..f58bb49 100755 --- a/t/lib/complex.t +++ b/t/lib/complex.t @@ -5,6 +5,7 @@ # Regression tests for the new Math::Complex pacakge # -- Raphael Manfredi, Septemeber 1996 # -- Jarkko Hietaniemi Manfredi, March 1997 +# -- Dominic Dunlop, March 1997 (reduce virtual memory requirement only) BEGIN { chdir 't' if -d 't'; @INC = '../lib'; @@ -13,7 +14,7 @@ use Math::Complex; $test = 0; $| = 1; -$script = ''; +@script = (); my $eps = 1e-4; # for example root() is quite bad while () { @@ -48,7 +49,7 @@ while () { } print "1..$test\n"; -eval $script; +eval join '', @script; die $@ if $@; sub test { @@ -57,13 +58,13 @@ sub test { my $i; for ($i = 0; $i < @args; $i++) { $val = value($args[$i]); - $script .= "\$z$i = $val;\n"; + push @script, "\$z$i = $val;\n"; } if (defined $z) { $args = "'$op'"; # Really the value $try = "abs(\$z0 - \$z1) <= $eps ? \$z1 : \$z0"; - $script .= "\$res = $try; "; - $script .= "check($test, $args[0], \$res, \$z$#args, $args);\n"; + push @script, "\$res = $try; "; + push @script, "check($test, $args[0], \$res, \$z$#args, $args);\n"; } else { my ($try, $args); if (@args == 2) { @@ -73,8 +74,8 @@ sub test { $try = ($op =~ /^\w/) ? "$op(\$z0, \$z1)" : "\$z0 $op \$z1"; $args = "'$args[0]', '$args[1]'"; } - $script .= "\$res = $try; "; - $script .= "check($test, '$try', \$res, \$z$#args, $args);\n"; + push @script, "\$res = $try; "; + push @script, "check($test, '$try', \$res, \$z$#args, $args);\n"; } } @@ -88,7 +89,7 @@ sub set { for ($i = 0; $i < @set; $i++) { push(@{$valref}, $set[$i]); my $val = value($set[$i]); - $script .= "\$s$i = $val;\n"; + push @script, "\$s$i = $val;\n"; push(@{$setref}, "\$s$i"); } }