Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: The arbitrary operator maker

by jimt (Chaplain)
on Nov 22, 2006 at 20:44 UTC ( #585607=note: print w/replies, xml ) Need Help??


in reply to Re: The arbitrary operator maker
in thread The arbitrary operator maker

I have and it's not. Or, at least, it's not faster. But it's also more general purpose.

my $op = '+'; my $add_5_things = arbitrary_operator_maker($op, 5); my @list_5 = (1..5); timethese(1000000, { 'add_5_things elements cached' => sub { $add_5_things->(@list_5); }, 'add_5_things elements dispatched' => sub { my $add_5_things = arbitrary_operator_maker($op, 5); $add_5_things->(@list_5); }, 'multi_add 5 elements' => sub { multi_add(@list_5); }, 'reduce' => sub { reduce { $a + $b} @list_5; } }); Benchmark: timing 1000000 iterations of add_5_things elements cached, +add_5_things elements dispatched, multi_add 5 elements, reduce... add_5_things elements cached: 0 wallclock secs ( 0.99 usr + 0.00 sys + = 0.99 CPU) @ 1010101.01/s (n=1000000) add_5_things elements dispatched: 2 wallclock secs ( 2.94 usr + -0.00 + sys = 2.94 CPU) @ 340136.05/s (n=1000000) multi_add 5 elements: 2 wallclock secs ( 2.52 usr + 0.01 sys = 2.53 + CPU) @ 395256.92/s (n=1000000) reduce: 4 wallclock secs ( 3.24 usr + 0.01 sys = 3.25 CPU) @ 30 +7692.31/s (n=1000000)

Or, with a bigger set:

my $op = '+'; my $add_500_things = arbitrary_operator_maker($op, 500); my @list_500 = (1..500); timethese(10000, { 'add_500_things elements cached' => sub { $add_500_things->(@list_500); }, 'add_500_things elements dispatched' => sub { my $add_500_things = arbitrary_operator_maker($op, 500); $add_500_things->(@list_500); }, 'multi_add 5 elements' => sub { multi_add(@list_500); }, 'reduce' => sub { reduce { $a + $b} @list_500; } }); Benchmark: timing 10000 iterations of add_500_things elements cached, +add_500_things elements dispatched, multi_add 5 elements, reduce... add_500_things elements cached: 1 wallclock secs ( 0.72 usr + 0.00 s +ys = 0.72 CPU) @ 13888.89/s (n=10000) add_500_things elements dispatched: 0 wallclock secs ( 0.74 usr + 0. +00 sys = 0.74 CPU) @ 13513.51/s (n=10000) multi_add 5 elements: 0 wallclock secs ( 1.03 usr + 0.00 sys = 1.03 + CPU) @ 9708.74/s (n=10000) reduce: 1 wallclock secs ( 1.18 usr + 0.00 sys = 1.18 CPU) @ 84 +74.58/s (n=10000)

Of course, it's also much more general purpose than the arbitrary_operator_maker is, which is highly specialized. But for these tests, though, reduce was the slowest of the bunch. Benchmarks are your friend.

Replies are listed 'Best First'.
Re^3: The arbitrary operator maker
by diotalevi (Canon) on Nov 22, 2006 at 20:50 UTC

    In your final comparison between reduce and other operations you note that being specialized allows you to be faster. Sure. Ok. But you didn't buy much with that.

    ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

      It is faster and doesn't use XS. Of the two, the latter I find to be a bigger advantage.

      - tye        

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://585607]
help
Chatterbox?
[1nickt]: the tick that can make you a vegetarian
[perldigious]: Your Mother: Yeah, I have a tool for ticks that I use (mostly on my dogs thankfully), but it's just a cheapo one I got from my vets office... it works pretty good though.
erix saw a tick in a natural history museum collected from the scrotum of the curator (it was removed)
[Your Mother]: The exhibit, the tick, or the scrotum?
[erix]: (the man is even a paleontologist )
[1nickt]: erix unfortunately that's there favourite spot. That's why they are usually spotted crawling *up* your leg.
[erix]: ha, the tick and, as it happens, also the curator (now a professor of Paleont.)
[1nickt]: s/there/their/, ugh sorry.
[Your Mother]: Heh. The only one I ever had on me, I caught on my shin, headed north.
erix looks nervously I got away cleanly from my run , it seems :)

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (12)
As of 2017-05-24 13:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?