Schuyler D. Erle on Tue, 6 Jun 2000 22:23:20 -0400 (EDT)


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Memory usage in Perl: TMTOWTDI strikes back!


Question:

I'm revising an HTML template parser I've been working on for I don't know how long, and I thank my-deity-of-choice repeatedly that, as mjd likes to point out, Perl's subs are first-class. My parser builds lots of closures that put into the parse tree, and get called during the rendering stage. The thing is, a lot of these closures could probably be replaced with named subroutines plus arguments, i.e. :

	sub some_parse_routine
	{
		my ($a, @b, %c);
		return sub { ... }
	}
	.
	.
	.
	my $code = some_parse_routine(...);
	$render->$code(...);

... is equivalent for my purposes to ....

	sub some_parse_routine
	{
		my ($a, @b, %c);
		return [ \&some_sub_to_call_later, \$a, \@b, \%c ];
	}
	.
	.
	.
	my $args = some_parse_routine(...);
	my $code = shift @$args;
	$render->$code(@$args, ...);	# $code could also be a method name!

The question is: Which method is more efficient in terms of (a) speed, and especially (b) memory usage? In general, how do I find out/compare memory consumption by thingy? Also, the closure gets compiled at compile-time, right? How do the lexical thingies get in there, then? Any discussion of this topic would be much appreciated.

SDE
**Majordomo list services provided by PANIX <URL:http://www.panix.com>**
**To Unsubscribe, send "unsubscribe phl" to majordomo@lists.pm.org**