renard wrote:
BE AWARE THAT THE BENCHMARK PROVIDES INCORRECT RESULTS.
Thnaks, I was aware of that, but still wanted a general idea :)
The tested code is within an anonymous subroutine while this does
executes, the results differ dramitcally from the results when the
tested code is enclosed withi
The slice version took about 10 seconds, the grep one took more than 1
minute.
Marcello
Thanks Marcello!
Your example, John's. and renards have been very helpful to help see the
point someone else was trying to make about watching what you include in
your benchmark.
I appreciate your time :)
JupiterHost.Net ha scritto:
In benchmarking some code I've come across something I did not expect:
slice:
use strict;
use warnings;
my @k=qw(1 2 3 4 5 6);
my %n;@[EMAIL PROTECTED] = @k;
print "hi" if exists $n{1};
print "hi" if exists $n{3};
print "hi" if exists $n{5};
print "hi" if exists $n{7};
p
> Lawrence Statton wrote:
[snip]
Gotcha, thx
So then can you suggest a method of benchmarking these 2 methods that
would be more accurate?
I believe John's solution was excellent at illustrating th deficiencies
in the way I was doing it and supplying a solution and answering my
question all at
#!/usr/bin/perl
use warnings;
use strict;
use Benchmark 'cmpthese';
my @k = qw( 1 2 3 4 5 6 );
cmpthese( -10, {
exists => sub {
my $count = 0;
my %hash;
@hash{ @k } = ();
for my $num ( 1, 3, 5, 7, 9, 11 ) {
$count++ if exists $hash{ $num };
JupiterHost.Net wrote:
In benchmarking some code I've come across something I did not expect:
slice:
use strict;
use warnings;
my @k=qw(1 2 3 4 5 6);
my %n;@[EMAIL PROTECTED] = @k;
print "hi" if exists $n{1};
print "hi" if exists $n{3};
print "hi" if exists $n{5};
print "hi" if exists $n{7};
print
> Thanks for your input :)
No problem -- I really do enjoy this. However, I do have some actual
WORK that I need to do today :(
> > Finally, there were serious errors in your methodology in your
>
> Serious? I thought "in the Big Picture, it won't matter a gnats eyebrow." :)
And I stand by t
Thanks for your input :)
Finally, there were serious errors in your methodology in your
Serious? I thought "in the Big Picture, it won't matter a gnats eyebrow." :)
original benchmark. It turns out the printing dominated the total
That is why I made both identical except for the difference I'm
co
Bakken, Luke wrote:
You have to stop spending so much time playing with all this bogus
benchmarking :)
It not bogus :) Its an example to find the best method for a project.
If you prefer I'll ask the question I was trying to answer with the
benchmark:
Assuming you have an array of 0-15 elements
print "hi" if $n{11};
What if it's value is 0, '', or undef? It would exist but your
test
would miss it :)
In that case "defined" would be a beter function to use.
ok, but I'm still not interested in the value of the key I;'m interested
inthe key, so why not exists since its made for hashes :)
> > You have to stop spending so much time playing with all this bogus
> > benchmarking :)
>
> It not bogus :) Its an example to find the best method for a project.
>
And I'll reiterate more clearly. Benchmarking is *not* the tool to find
the best method.
The BEST method for a project is that
- Original Message -
From: "JupiterHost.Net" <[EMAIL PROTECTED]>
Date: Tuesday, January 25, 2005 11:37 am
Subject: Re: hash slice/exists vs. grep benchmark weirdness...
>
> >
> > Just as an FYI, you don't need "exists" in your code at all.
> > You have to stop spending so much time playing with all this bogus
> > benchmarking :)
>
> It not bogus :) Its an example to find the best method for a project.
>
> If you prefer I'll ask the question I was trying to answer with the
> benchmark:
>
> Assuming you have an array of 0-15 elemen
[EMAIL PROTECTED] suggested:
> Just as an FYI, you don't need "exists" in your code at all.
> It is just a waste of time in your example. Should be beter writen as:
>
> print "hi" if $n{11};
Bad idea, if you consider this:
$n{'oops'} = 0;
print "hi" if $n{'oops'};
print "ho" if exists $n{'oop
Just as an FYI, you don't need "exists" in your code at all. It is just a
waste of time in your example. Should be beter writen as:
print "hi" if $n{11};
What if it's value is 0, '', or undef? It would exist but your test
would miss it :)
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additio
- Original Message -
From: "JupiterHost.Net" <[EMAIL PROTECTED]>
Date: Tuesday, January 25, 2005 11:01 am
Subject: Re: hash slice/exists vs. grep benchmark weirdness...
> > You have to stop spending so much time playing with all this bogus
> > benchmarking :)
You have to stop spending so much time playing with all this bogus
benchmarking :)
It not bogus :) Its an example to find the best method for a project.
If you prefer I'll ask the question I was trying to answer with the
benchmark:
Assuming you have an array of 0-15 elements is it quicker/more ef
> In benchmarking some code I've come across something I did not expect:
>
You have to stop spending so much time playing with all this bogus
benchmarking :)
> slice:
> use strict;
> use warnings;
> my @k=qw(1 2 3 4 5 6);
> my %n;@[EMAIL PROTECTED] = @k;
> print "hi" if exists $n{1};
> print "h
18 matches
Mail list logo