[32349] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 3616 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Feb 21 16:09:46 2012

Date: Tue, 21 Feb 2012 13:09:10 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 21 Feb 2012     Volume: 11 Number: 3616

Today's topics:
        a question about efficiency <kiuhnm03.4t.yahoo.it>
    Re: a question about efficiency <rweikusat@mssgmbh.com>
    Re: a question about efficiency <kiuhnm03.4t.yahoo.it>
    Re: a question about efficiency <jurgenex@hotmail.com>
    Re: a question about efficiency <rweikusat@mssgmbh.com>
    Re: a question about efficiency <ben@morrow.me.uk>
    Re: a question about efficiency (Tim McDaniel)
    Re: a question about efficiency <kiuhnm03.4t.yahoo.it>
    Re: a question about efficiency <kiuhnm03.4t.yahoo.it>
    Re: a question about efficiency <kiuhnm03.4t.yahoo.it>
    Re: a question about efficiency <rweikusat@mssgmbh.com>
    Re: a question about efficiency (Tim McDaniel)
    Re: a question about efficiency <kiuhnm03.4t.yahoo.it>
    Re: a question about efficiency <rweikusat@mssgmbh.com>
    Re: Can't connect to 'localhost' in IO::Socket <w.c.humann@arcor.de>
        Perl search string <cldplmr.74@gmail.com>
    Re: Perl search string <jurgenex@hotmail.com>
    Re: Perl search string <justin.1201@purestblue.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Tue, 21 Feb 2012 13:29:23 +0100
From: Kiuhnm <kiuhnm03.4t.yahoo.it>
Subject: a question about efficiency
Message-Id: <4f438e22$0$1390$4fafbaef@reader2.news.tin.it>

Hi,
I've just started to learn Perl. Here's my first question.

Please look at this code:
--->
   my $len1;
   foreach (keys %ENV) {
     if (length $_ > $len1) { $len1 = length $_ }}
<---
Does Perl execute "length $_" twice or once?
Should I use
   if ((my $l = length $_) > $len1) { $len1 = $l }}
instead?

Kiuhnm


------------------------------

Date: Tue, 21 Feb 2012 13:47:14 +0000
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: a question about efficiency
Message-Id: <87ipj0nvrx.fsf@sapphire.mobileactivedefense.com>

Kiuhnm <kiuhnm03.4t.yahoo.it> writes:
> Please look at this code:
> --->
>   my $len1;
>   foreach (keys %ENV) {
>     if (length $_ > $len1) { $len1 = length $_ }}
> <---
> Does Perl execute "length $_" twice or once?

Twice (at least for 5.10.1).

> Should I use
>   if ((my $l = length $_) > $len1) { $len1 = $l }}

Certainly not. Even when implemented in a sensible way, the idea to
use an additional variable to keep the length results in somewhat
slower code which is to be expected because it makes Perl perform a
little more work (everything it did for the other case plus an
additional assignment). Creating and destroying a my-variable each
time the if-statement is executed makes that A LOT more work.

NB: This is isn't necessarily true for all other subroutines,
especially, 'user subroutines' implemented in Perl.

-----------
use Benchmark;

timethese(-10, {
	       a => sub {
		     my $len1;
		     
		     length($_) > $len1 and $len1 = length($_) for keys(%ENV);
		    },

	       c => sub {
		   my ($l1, $l0);

		   ($l0 = length($_)) > $l1 and $l1 = $l0 for keys(%ENV);
	       },

		d => sub {
		    my $l1;

		    for (keys(%ENV)) {
			if ((my $l = length($_)) > $l1) { $l1 = $; }
		    }
		}
	       });
-------------


------------------------------

Date: Tue, 21 Feb 2012 16:01:55 +0100
From: Kiuhnm <kiuhnm03.4t.yahoo.it>
Subject: Re: a question about efficiency
Message-Id: <4f43b1e3$0$1390$4fafbaef@reader2.news.tin.it>

On 2/21/2012 14:47, Rainer Weikusat wrote:
> Kiuhnm<kiuhnm03.4t.yahoo.it>  writes:
>> Please look at this code:
>> --->
>>    my $len1;
>>    foreach (keys %ENV) {
>>      if (length $_>  $len1) { $len1 = length $_ }}
>> <---
>> Does Perl execute "length $_" twice or once?
>
> Twice (at least for 5.10.1).
>
>> Should I use
>>    if ((my $l = length $_)>  $len1) { $len1 = $l }}
>
> Certainly not. Even when implemented in a sensible way, the idea to
> use an additional variable to keep the length results in somewhat
> slower code which is to be expected because it makes Perl perform a
> little more work (everything it did for the other case plus an
> additional assignment). Creating and destroying a my-variable each
> time the if-statement is executed makes that A LOT more work.

Ops... I forgot that Perl doesn't use null-terminated strings. strlen() 
is an O(n) operation in C, as you well know.

> NB: This is isn't necessarily true for all other subroutines,
> especially, 'user subroutines' implemented in Perl.
>
> -----------
> use Benchmark;
>
> timethese(-10, {
> 	       a =>  sub {
> 		     my $len1;
> 		
> 		     length($_)>  $len1 and $len1 = length($_) for keys(%ENV);

Interesting. That syntax is new to me, but makes sense. My only doubt is 
whether "and" and "&&" are the same thing. It appears so.

> 		    },
>
> 	       c =>  sub {
> 		   my ($l1, $l0);
>
> 		   ($l0 = length($_))>  $l1 and $l1 = $l0 for keys(%ENV);
> 	       },
>
> 		d =>  sub {
> 		    my $l1;
>
> 		    for (keys(%ENV)) {
> 			if ((my $l = length($_))>  $l1) { $l1 = $; }
> 		    }
> 		}
> 	       });
> -------------

If this isn't another Perl feature I don't know about, you forgot an 'l' 
in your last assignment. On my PC, the 'l' improves the efficiency. I 
guess even undef->0 conversions count.
Anyway, taking that $l out of the loop, makes the last option the fastest.
The "objects" after the "fat commas" are (pointers to?) closures?

Try this code:

-------->
use Benchmark;

timethese(-5, {
	       a => sub {
		     my $len1;
		
		     length($_) > $len1 and $len1 = length($_) for keys(%ENV);
		    },

	       c => sub {
		   my ($l1, $l0);

		   ($l0 = length($_)) > $l1 and $l1 = $l0 for keys(%ENV);
	       },

		d => sub {
		    my $l1;

		    for (keys(%ENV)) {
			if ((my $l = length($_)) > $l1) { $l1 = $l; }
		    }},

		e => sub {
		    my ($l1, $l);

		    for (keys(%ENV)) {
			if (($l = length($_)) > $l1) { $l1 = $l; }
		    }},
		
    		f => sub {
		    my $l1;

		    for (keys(%ENV)) {
			if (length($_) > $l1) { $l1 = length($_); }
		    }
		}
	  });
<--------

'e' wins on my PC.

Kiuhnm


------------------------------

Date: Tue, 21 Feb 2012 07:09:43 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: a question about efficiency
Message-Id: <kgc7k7d2cpc1gk5gelnhktc2a51ij08jao@4ax.com>

Kiuhnm <kiuhnm03.4t.yahoo.it> wrote:
>Hi,
>I've just started to learn Perl. Here's my first question.
>
>Please look at this code:
>--->
>   my $len1;
>   foreach (keys %ENV) {
>     if (length $_ > $len1) { $len1 = length $_ }}
><---
>Does Perl execute "length $_" twice or once?

In Perl the lenght of a string is O(1). If you read it once or twice
really doesn't make any perceptible difference.
All the other operations in that loop from comparing the values to
executing the jump for the conditional code are significantly more
expensive.

If you have already exhausted all algorithmic optimizations and your
code is still too slow and you really really think you need optimization
on that level, then you should use a different programming language
instead, e.g. assembler or C.

jue


------------------------------

Date: Tue, 21 Feb 2012 15:34:57 +0000
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: a question about efficiency
Message-Id: <87y5rwmc7y.fsf@sapphire.mobileactivedefense.com>

Kiuhnm <kiuhnm03.4t.yahoo.it> writes:
>> 		d =>  sub {
>> 		    my $l1;
>>
>> 		    for (keys(%ENV)) {
>> 			if ((my $l = length($_))>  $l1) { $l1 = $; }
>> 		    }
>> 		}
>> 	       });
>> -------------
>
> If this isn't another Perl feature I don't know about, you forgot an
> l' in your last assignment. On my PC, the 'l' improves the
> efficiency.

Not significantly (if at all).

> I guess even undef->0 conversions count.
> Anyway, taking that $l out of the loop, makes the last option the fastest.
> The "objects" after the "fat commas" are (pointers to?) closures?
>
> Try this code:
>
> -------->
> use Benchmark;
>
> timethese(-5, {

[...]

> 	  });
> <--------
>
> 'e' wins on my PC.

You won't really get anything useful when running this only for 5
seconds and the results aren't really stable even when using a much
larger count:

[rw@sapphire]/tmp $perl c.pl
Benchmark: running a, c, d, e, f for at least 20 CPU seconds...
         a: 20 wallclock secs (20.66 usr +  0.12 sys = 20.78 CPU) @ 207958.47/s (n=4321377)
         c: 20 wallclock secs (19.97 usr +  0.03 sys = 20.00 CPU) @ 203267.70/s (n=4065354)
         d: 21 wallclock secs (20.83 usr +  0.12 sys = 20.95 CPU) @ 169893.65/s (n=3559272)
         e: 21 wallclock secs (20.89 usr +  0.06 sys = 20.95 CPU) @ 202873.51/s (n=4250200)
         f: 20 wallclock secs (20.87 usr +  0.09 sys = 20.96 CPU) @ 207976.19/s (n=4359181)
[rw@sapphire]/tmp $perl c.pl
Benchmark: running a, c, d, e, f for at least 20 CPU seconds...
         a: 22 wallclock secs (21.58 usr +  0.11 sys = 21.69 CPU) @ 200191.47/s (n=4342153)
         c: 21 wallclock secs (20.70 usr +  0.05 sys = 20.75 CPU) @ 192327.61/s (n=3990798)
         d: 20 wallclock secs (20.72 usr +  0.07 sys = 20.79 CPU) @ 149736.70/s (n=3113026)
         e: 22 wallclock secs (21.96 usr +  0.04 sys = 22.00 CPU) @ 187564.00/s (n=4126408)
         f: 19 wallclock secs (20.07 usr +  0.10 sys = 20.17 CPU) @ 201994.50/s (n=4074229)

Especially, the relative positions of of (a, f) and (c, e) where the
other way around for most of the runs I did. The result is roughly
that a and f come out first, then, c and e, and then d, which is by
far the worst.


------------------------------

Date: Tue, 21 Feb 2012 15:44:08 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: a question about efficiency
Message-Id: <8nqc19-dp2.ln1@anubis.morrow.me.uk>


Quoth Kiuhnm <kiuhnm03.4t.yahoo.it>:
> On 2/21/2012 14:47, Rainer Weikusat wrote:
> >
> > 		     length($_)>  $len1 and $len1 = length($_) for keys(%ENV);
> 
> Interesting. That syntax is new to me, but makes sense.

You realise the 'and' short-circuits, as in C and shell, right? (It's
not an uncommon idiom in shell, either.)

> My only doubt is whether "and" and "&&" are the same thing. It appears
> so.

They are not quite. '&&' has relatively high precedence (it binds
tightly); 'and' has extremely low precedence. This is an example of when
it matters: if Rainer had used '&&' instead it would have been
equivalent to

    ((length($_) > $len1) && $len1) = length($_)

which is not at all the same as the

    (length($_) > $len1) and ($len1 = length($_))

he actually wrote.

I find the B::Deparse module useful for checking precedence:

    perl -MO=Deparse,-p -e'length($_) > $len1 && $len1 = length($_)'
    (((length($_) > $len1) && $len1) = length($_));

Adding just '-MO=Deparse' to a perl command-line makes perl print a
compiled-and-decompiled version of your program instead of running it;
adding the ',-p' option to Deparse makes it put in all possible
parentheses.

It is usual to use '&&' when you want a logical operator, and 'and' when
you're using it for control flow.

> > 		d =>  sub {
> > 		    my $l1;
> >
> > 		    for (keys(%ENV)) {
> > 			if ((my $l = length($_))>  $l1) { $l1 = $; }
> > 		    }
> > 		}
> > 	       });
> 
> If this isn't another Perl feature I don't know about, you forgot an 'l' 
> in your last assignment.

Well, there *is* a $; variable, with an extremely obscure use, but
somehow I doubt that's what Rainer meant... :)

<snip>
> The "objects" after the "fat commas" are (pointers to?) closures?

Yes. In Perl we would normally call them 'references' rather than
'pointers', but it's very much the same thing. (A Perl ref is refcounted
and garbage-collected, and so a good deal safer than a C pointer.)

(Technically they aren't closures in this instance, just anonymous
subroutines, because they don't close over any outer variables. This is
nearly never an important distinction.)

Ben



------------------------------

Date: Tue, 21 Feb 2012 16:38:27 +0000 (UTC)
From: tmcd@panix.com (Tim McDaniel)
Subject: Re: a question about efficiency
Message-Id: <ji0ha3$4fo$1@reader1.panix.com>

In article <4f438e22$0$1390$4fafbaef@reader2.news.tin.it>,
Kiuhnm  <kiuhnm03.4t.yahoo.it> wrote:
>Hi,
>I've just started to learn Perl. Here's my first question.
>
>Please look at this code:
>--->
>   my $len1;
>   foreach (keys %ENV) {
>     if (length $_ > $len1) { $len1 = length $_ }}
><---
>Does Perl execute "length $_" twice or once?
>Should I use
>   if ((my $l = length $_) > $len1) { $len1 = $l }}
>instead?

Some great answers have been given.  I'll just add two small points:

"Micro-optimization leads to micro-results."

For doing max and min, I personally prefer a more parallel-looking
structure like
    if ($len1 < length $_) {
        $len1 = length $_;
    }

-- 
Tim McDaniel, tmcd@panix.com


------------------------------

Date: Tue, 21 Feb 2012 18:36:12 +0100
From: Kiuhnm <kiuhnm03.4t.yahoo.it>
Subject: Re: a question about efficiency
Message-Id: <4f43d60b$0$1387$4fafbaef@reader2.news.tin.it>

On 2/21/2012 16:44, Ben Morrow wrote:
> Quoth Kiuhnm<kiuhnm03.4t.yahoo.it>:
>> On 2/21/2012 14:47, Rainer Weikusat wrote:
>>>
>>> 		length($_)>   $len1 and $len1 = length($_) for keys(%ENV);
>>
>> Interesting. That syntax is new to me, but makes sense.
>
> You realise the 'and' short-circuits, as in C and shell, right? (It's
> not an uncommon idiom in shell, either.)

Of course. What strikes me is that strange "for". That's kind of cool, 
though. Finally I can omit those hideous curly braces.

> They are not quite. '&&' has relatively high precedence (it binds
> tightly); 'and' has extremely low precedence. This is an example of when
> it matters: if Rainer had used '&&' instead it would have been
> equivalent to
[...]
> It is usual to use '&&' when you want a logical operator, and 'and' when
> you're using it for control flow.

Thank you. I didn't know that. I'm still at the trial-and-error stage. 
"Learning Perl" won't give me too many details until my fragile mind is 
ready to assimilate them :)

[...]
> Yes. In Perl we would normally call them 'references' rather than
> 'pointers', but it's very much the same thing. (A Perl ref is refcounted
> and garbage-collected, and so a good deal safer than a C pointer.)

Like in C#. Safety comes at a cost, though. It's not easy to write a 
micro-kernel in C# or in Perl ;)

> (Technically they aren't closures in this instance, just anonymous
> subroutines, because they don't close over any outer variables. This is
> nearly never an important distinction.)

Well, theoretically, a closure doesn't need to "capture" outer variables 
to be called a closure. But you already know that. I guess it depends on 
how a community see things.

Kiuhnm


------------------------------

Date: Tue, 21 Feb 2012 18:43:46 +0100
From: Kiuhnm <kiuhnm03.4t.yahoo.it>
Subject: Re: a question about efficiency
Message-Id: <4f43d7d1$0$1380$4fafbaef@reader2.news.tin.it>

On 2/21/2012 16:34, Rainer Weikusat wrote:
> Kiuhnm<kiuhnm03.4t.yahoo.it>  writes:
>>> 		d =>   sub {
>>> 		    my $l1;
>>>
>>> 		    for (keys(%ENV)) {
>>> 			if ((my $l = length($_))>   $l1) { $l1 = $; }
>>> 		    }
>>> 		}
>>> 	       });
>>> -------------
>>
>> If this isn't another Perl feature I don't know about, you forgot an
>> l' in your last assignment. On my PC, the 'l' improves the
>> efficiency.
>
> Not significantly (if at all).

It makes a huge difference on my configuration (~30%).

> You won't really get anything useful when running this only for 5
> seconds and the results aren't really stable even when using a much
> larger count:
>
> [rw@sapphire]/tmp $perl c.pl
> Benchmark: running a, c, d, e, f for at least 20 CPU seconds...
>           a: 20 wallclock secs (20.66 usr +  0.12 sys = 20.78 CPU) @ 207958.47/s (n=4321377)
>           c: 20 wallclock secs (19.97 usr +  0.03 sys = 20.00 CPU) @ 203267.70/s (n=4065354)
>           d: 21 wallclock secs (20.83 usr +  0.12 sys = 20.95 CPU) @ 169893.65/s (n=3559272)
>           e: 21 wallclock secs (20.89 usr +  0.06 sys = 20.95 CPU) @ 202873.51/s (n=4250200)
>           f: 20 wallclock secs (20.87 usr +  0.09 sys = 20.96 CPU) @ 207976.19/s (n=4359181)
> [rw@sapphire]/tmp $perl c.pl
> Benchmark: running a, c, d, e, f for at least 20 CPU seconds...
>           a: 22 wallclock secs (21.58 usr +  0.11 sys = 21.69 CPU) @ 200191.47/s (n=4342153)
>           c: 21 wallclock secs (20.70 usr +  0.05 sys = 20.75 CPU) @ 192327.61/s (n=3990798)
>           d: 20 wallclock secs (20.72 usr +  0.07 sys = 20.79 CPU) @ 149736.70/s (n=3113026)
>           e: 22 wallclock secs (21.96 usr +  0.04 sys = 22.00 CPU) @ 187564.00/s (n=4126408)
>           f: 19 wallclock secs (20.07 usr +  0.10 sys = 20.17 CPU) @ 201994.50/s (n=4074229)
>
> Especially, the relative positions of of (a, f) and (c, e) where the
> other way around for most of the runs I did. The result is roughly
> that a and f come out first, then, c and e, and then d, which is by
> far the worst.

Well, the results are quite stable on *my* configuation:

Benchmark: running a, c, d, e, f for at least 20 CPU seconds...
          a: 22 wallclock secs (20.90 usr +  0.00 sys = 20.90 CPU) @ 
81467.61/s (n=1702999)
          c: 22 wallclock secs (21.09 usr +  0.00 sys = 21.09 CPU) @ 
79958.99/s (n=1686415)
          d: 21 wallclock secs (21.12 usr +  0.00 sys = 21.12 CPU) @ 
68458.93/s (n=1446058)
          e: 20 wallclock secs (21.04 usr +  0.00 sys = 21.04 CPU) @ 
84107.30/s (n=1769954)
          f: 20 wallclock secs (21.43 usr +  0.00 sys = 21.43 CPU) @ 
81938.84/s (n=1756277)

Benchmark: running a, c, d, e, f for at least 20 CPU seconds...
          a: 22 wallclock secs (21.29 usr +  0.00 sys = 21.29 CPU) @ 
81483.14/s (n=1735102)
          c: 21 wallclock secs (21.09 usr +  0.00 sys = 21.09 CPU) @ 
80093.83/s (n=1689259)
          d: 20 wallclock secs (21.03 usr +  0.00 sys = 21.03 CPU) @ 
68558.51/s (n=1441717)
          e: 22 wallclock secs (21.05 usr +  0.00 sys = 21.05 CPU) @ 
84064.81/s (n=1769144)
          f: 22 wallclock secs (21.25 usr +  0.02 sys = 21.26 CPU) @ 
82042.33/s (n=1744384)

Benchmark: running a, c, d, e, f for at least 20 CPU seconds...
          a: 21 wallclock secs (20.90 usr +  0.00 sys = 20.90 CPU) @ 
81467.61/s (n=1702999)
          c: 20 wallclock secs (21.00 usr +  0.00 sys = 21.00 CPU) @ 
80486.76/s (n=1690061)
          d: 22 wallclock secs (21.12 usr +  0.00 sys = 21.12 CPU) @ 
68882.97/s (n=1454946)
          e: 22 wallclock secs (21.22 usr +  0.00 sys = 21.22 CPU) @ 
84137.82/s (n=1785068)
          f: 22 wallclock secs (21.36 usr +  0.00 sys = 21.36 CPU) @ 
82275.52/s (n=1757076)

And the results won't change if I go from 20 s. to "just" 5 s.:

Benchmark: running a, c, d, e, f for at least 5 CPU seconds...
          a:  5 wallclock secs ( 5.27 usr +  0.00 sys =  5.27 CPU) @ 
81488.15/s (n=429687)
          c:  5 wallclock secs ( 5.23 usr +  0.00 sys =  5.23 CPU) @ 
80314.20/s (n=419722)
          d:  4 wallclock secs ( 5.34 usr +  0.00 sys =  5.34 CPU) @ 
68570.09/s (n=365890)
          e:  6 wallclock secs ( 5.26 usr +  0.00 sys =  5.26 CPU) @ 
84131.25/s (n=442278)
          f:  6 wallclock secs ( 5.35 usr +  0.00 sys =  5.35 CPU) @ 
82214.91/s (n=439932)

Why should they?

Kiuhnm


------------------------------

Date: Tue, 21 Feb 2012 19:05:46 +0100
From: Kiuhnm <kiuhnm03.4t.yahoo.it>
Subject: Re: a question about efficiency
Message-Id: <4f43dcfa$0$1379$4fafbaef@reader2.news.tin.it>

On 2/21/2012 17:38, Tim McDaniel wrote:
> Some great answers have been given.  I'll just add two small points:
>
> "Micro-optimization leads to micro-results."

I believe that's not entirely true. Sometimes changing a comma will 
speed up one's program considerably.

> For doing max and min, I personally prefer a more parallel-looking
> structure like
>      if ($len1 < length $_) {
>          $len1 = length $_;
>      }

I still hate the two braces (6 keys on my keyboard), but that's 
undeniably much more readable.

Kiuhnm


------------------------------

Date: Tue, 21 Feb 2012 18:16:18 +0000
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: a question about efficiency
Message-Id: <878vjwm4r1.fsf@sapphire.mobileactivedefense.com>


[...]

>> You won't really get anything useful when running this only for 5
>> seconds and the results aren't really stable even when using a much
>> larger count:
>>
>> [rw@sapphire]/tmp $perl c.pl
>> Benchmark: running a, c, d, e, f for at least 20 CPU seconds...
>>           a: 20 wallclock secs (20.66 usr +  0.12 sys = 20.78 CPU) @ 207958.47/s (n=4321377)
>>           c: 20 wallclock secs (19.97 usr +  0.03 sys = 20.00 CPU) @ 203267.70/s (n=4065354)
>>           d: 21 wallclock secs (20.83 usr +  0.12 sys = 20.95 CPU) @ 169893.65/s (n=3559272)
>>           e: 21 wallclock secs (20.89 usr +  0.06 sys = 20.95 CPU) @ 202873.51/s (n=4250200)
>>           f: 20 wallclock secs (20.87 usr +  0.09 sys = 20.96 CPU) @ 207976.19/s (n=4359181)
>> [rw@sapphire]/tmp $perl c.pl
>> Benchmark: running a, c, d, e, f for at least 20 CPU seconds...
>>           a: 22 wallclock secs (21.58 usr +  0.11 sys = 21.69 CPU) @ 200191.47/s (n=4342153)
>>           c: 21 wallclock secs (20.70 usr +  0.05 sys = 20.75 CPU) @ 192327.61/s (n=3990798)
>>           d: 20 wallclock secs (20.72 usr +  0.07 sys = 20.79 CPU) @ 149736.70/s (n=3113026)
>>           e: 22 wallclock secs (21.96 usr +  0.04 sys = 22.00 CPU) @ 187564.00/s (n=4126408)
>>           f: 19 wallclock secs (20.07 usr +  0.10 sys = 20.17 CPU) @ 201994.50/s (n=4074229)
>>
>> Especially, the relative positions of of (a, f) and (c, e) where the
>> other way around for most of the runs I did. The result is roughly
>> that a and f come out first, then, c and e, and then d, which is by
>> far the worst.
>
> Well, the results are quite stable on *my* configuation:

 ... which would server as further indication that they are not. Also,
the average difference between two successive value supposedly
measuring the same quantity varies between 17.2 (a) and 245.64
(d). How can this be for a deterministic phenomenon which has been
measured accurately?

> And the results won't change if I go from 20 s. to "just" 5 s.:
> Why should they?

Assuming that each individual measurement is composed of an accurate
part and some random error, it can be expected that the random errors
will tend to cancel out when a 'sufficiently large' number of
individual measurements is averaged. Which implies that longer
sequence ought to yield more accurate results.

But this looks suspiciciously like something people should learn when
they are about 16 or so ...


------------------------------

Date: Tue, 21 Feb 2012 19:36:23 +0000 (UTC)
From: tmcd@panix.com (Tim McDaniel)
Subject: Re: a question about efficiency
Message-Id: <ji0rnn$bum$1@reader1.panix.com>

In article <4f43d60b$0$1387$4fafbaef@reader2.news.tin.it>,
Kiuhnm  <kiuhnm03.4t.yahoo.it> wrote:
>Of course. What strikes me is that strange "for".

They're called "statement modifiers" in "man perlsyn".

>Finally I can omit those hideous curly braces.

If you think curly braces are "hideous", you might prefer using some
other language instead.  Or you might like Lingua::Romana::Perligata,
http://www.csse.monash.edu.au/~damian/papers/HTML/Perligata.html

-- 
Tim McDaniel, tmcd@panix.com


------------------------------

Date: Tue, 21 Feb 2012 20:57:40 +0100
From: Kiuhnm <kiuhnm03.4t.yahoo.it>
Subject: Re: a question about efficiency
Message-Id: <4f43f733$0$1388$4fafbaef@reader1.news.tin.it>

On 2/21/2012 19:16, Rainer Weikusat wrote:
> ... which would server as further indication that they are not. Also,
> the average difference between two successive value supposedly
> measuring the same quantity varies between 17.2 (a) and 245.64
> (d). How can this be for a deterministic phenomenon which has been
> measured accurately?
>
>> And the results won't change if I go from 20 s. to "just" 5 s.:
>> Why should they?
>
> Assuming that each individual measurement is composed of an accurate
> part and some random error, it can be expected that the random errors
> will tend to cancel out when a 'sufficiently large' number of
> individual measurements is averaged. Which implies that longer
> sequence ought to yield more accurate results.
>
> But this looks suspiciciously like something people should learn when
> they are about 16 or so ...

No need to be so defensive.

When one does these kinds of benchmarks he or she is not interested in 
knowing exactly how many ns his or her piece of code will take to 
execute but how much time it will take *on average*.
I don't know how reliable this benchmark is (is it cache-aware?, 
etc...), but it clearly shows that code (e) is slightly faster than the 
other codes on my configuration *on average*.
This means that if I use code (e) instead of codes (a)-(d) and (f) on a 
regular basis, my programs will probably be slightly faster.
It isn't worth it, of course.

Kiuhnm


------------------------------

Date: Tue, 21 Feb 2012 20:06:45 +0000
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: a question about efficiency
Message-Id: <8762f0kl2i.fsf@sapphire.mobileactivedefense.com>

Kiuhnm <kiuhnm03.4t.yahoo.it> writes:
> On 2/21/2012 19:16, Rainer Weikusat wrote:
>> ... which would server as further indication that they are not. Also,
>> the average difference between two successive value supposedly
>> measuring the same quantity varies between 17.2 (a) and 245.64
>> (d). How can this be for a deterministic phenomenon which has been
>> measured accurately?
>>
>>> And the results won't change if I go from 20 s. to "just" 5 s.:
>>> Why should they?
>>
>> Assuming that each individual measurement is composed of an accurate
>> part and some random error, it can be expected that the random errors
>> will tend to cancel out when a 'sufficiently large' number of
>> individual measurements is averaged. Which implies that longer
>> sequence ought to yield more accurate results.
>>
>> But this looks suspiciciously like something people should learn when
>> they are about 16 or so ...
>
> No need to be so defensive.

That was just my last attempt to assume ignorance instead of malice.
HAND.


------------------------------

Date: Tue, 21 Feb 2012 02:15:08 -0800 (PST)
From: Wolfram Humann <w.c.humann@arcor.de>
Subject: Re: Can't connect to 'localhost' in IO::Socket
Message-Id: <6c515a4e-dedc-4163-a5ba-498d88152f01@w4g2000vbc.googlegroups.com>

On 20 Feb., 16:17, Rainer Weikusat <rweiku...@mssgmbh.com> wrote:
> Usually no if the service is supposed to listening on a 'public'
> address (here supposed to mean anything except 127.0.0.1) anyway, see my
> remark about 'weak end-systems' above. Insofar desired, working
> source-based access control can either be provided by the application
> (by immediately closing connections from 'unwelcome' source addresses
> after accepting them) or with the help of some kind of host- or
> gateway-based packet filter.

Ok. Thanks again for your feedback,
Wolfram


------------------------------

Date: Tue, 21 Feb 2012 06:29:01 -0800 (PST)
From: Claudio Palmeri <cldplmr.74@gmail.com>
Subject: Perl search string
Message-Id: <1cd352ac-77aa-4feb-a6c3-88f54ed5ad1e@m7g2000vbw.googlegroups.com>

Hi all,

I'm newbie to Perl, and if it possible i'm searching for a simple
program that reads strings from one file and search it into another
and if it's found it will be write into a third one.

Thank you

Best Regards

Claudio


------------------------------

Date: Tue, 21 Feb 2012 07:12:13 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Perl search string
Message-Id: <6uc7k7ddgt7jul3m1tlfbccej0gtv7grjt@4ax.com>

Claudio Palmeri <cldplmr.74@gmail.com> wrote:
>I'm newbie to Perl, and if it possible i'm searching for a simple
>program that reads strings from one file 

perldoc -f open
perldoc -f readline

>and search it into another

perldoc -f open
perldoc -f readline
perldoc -f grep
perldoc perlop and look for the m operator

>and if it's found it will be write into a third one.

perldoc -f open
perldoc -f print

jue


------------------------------

Date: Tue, 21 Feb 2012 15:55:13 +0000
From: Justin C <justin.1201@purestblue.com>
Subject: Re: Perl search string
Message-Id: <1crc19-9ha.ln1@zem.masonsmusic.co.uk>

On 2012-02-21, Claudio Palmeri <cldplmr.74@gmail.com> wrote:
> Hi all,
>
> I'm newbie to Perl, and if it possible i'm searching for a simple
> program that reads strings from one file and search it into another
> and if it's found it will be write into a third one.

You won't find programs here, you write them yourself and ask for help
if it doesn't work as you expect.

The following documentation might be useful:
perldoc -f open
perldoc perlre

Please read the Posting Guidlines, posted here from time to time, they
can be viewed here: <URL:http://bit.ly/ydPryC>

   Justin.

-- 
Justin C, by the sea.


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 3616
***************************************


home help back first fref pref prev next nref lref last post