in reply to Re^5: Removing AUTOLOAD from CGI.pm
in thread Removing AUTOLOAD from CGI.pm

Hi

I wasn't criticizing CGI but trying to analyze the conditions for a new HTML DSL module. :)

I'm sure compilation speed shouldn't matter when generating closures. (I will add a benchmark later this day)

But CGI was designed for Perl 4 and I suppose Perl 4 wasn't able to closure... IIRC it didn't even have lexical variables.

Your wibble-tag is implemented as a method call, so it wouldn't depend on exporting and pre declaration anyway.

But DSLs are at the very least just syntactic sugar to avoid method calls.

> Anyway it's all gone now, or soon will be

Thanks for your work! :)

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)

PS: Je suis Charlie!

Replies are listed 'Best First'.
Re^7: Removing AUTOLOAD from CGI.pm (closure vs eval)
by LanX (Saint) on Feb 24, 2015 at 14:19 UTC
    > I'm sure compilation speed shouldn't matter when generating closures. (I will add a benchmark later this day)

    Here a simplified example which showed that installing subs with closures¹ is 5 times faster than eval.

    That's less dramatic than I thought, but eval performance also heavily depends on the length of code.

    So adding 10 no-ops already made eval 10 times slower while closure didn't change.

    use strict; use warnings; use Time::HiRes qw/time/; BEGIN { $\="\n"; my $count=1000; sub noop { }; my $start=time; sub tag_gen { my ($tag)=@_; sub { noop("Ipse Lorum"); noop("Ipse Lorum"); noop("Ipse Lorum"); noop("Ipse Lorum"); noop("Ipse Lorum"); noop("Ipse Lorum"); noop("Ipse Lorum"); noop("Ipse Lorum"); noop("Ipse Lorum"); noop("Ipse Lorum"); "<$tag>",@_,"</$tag>"; } } { no strict 'refs'; for my $x (1..$count) { my $tag="h$x"; *{$tag}=tag_gen($tag); } } print "Closure: ",time-$start; $start = time; for my $x (1..$count) { my $tag="H$x"; eval sprintf <<'__CODE__', $tag; sub %1$s { noop("Ipse Lorum"); noop("Ipse Lorum"); noop("Ipse Lorum"); noop("Ipse Lorum"); noop("Ipse Lorum"); noop("Ipse Lorum"); noop("Ipse Lorum"); noop("Ipse Lorum"); noop("Ipse Lorum"); noop("Ipse Lorum"); "<%1$s>",@_,"</%1$s>"; } __CODE__ } print "Eval: ",time-$start; } print h1 h2 "closure"; print H1 H2 "eval";

    output:

    Closure: 0.0279860496520996 Eval: 0.343567132949829 <h1><h2>closure</h2></h1> <H1><H2>eval</H2></H1>

    One has to keep in mind that 15-20 years ago machines were factor 1000 slower, i.e. auto loading was relevant.

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)

    PS: Je suis Charlie!

    update

    fixed bug with no-ops.

    ¹) currying to be precise