[31356] in Perl-Users-Digest
Perl-Users Digest, Issue: 2608 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 23 03:09:45 2009
Date: Wed, 23 Sep 2009 00:09:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 23 Sep 2009 Volume: 11 Number: 2608
Today's topics:
Active State 64-bit and Win32 Modules <pgodfrin@gmail.com>
Re: Active State 64-bit and Win32 Modules <bart.lateur@pandora.be>
Re: Active State 64-bit and Win32 Modules <pgodfrin@gmail.com>
Re: Active State 64-bit and Win32 Modules <sisyphus359@gmail.com>
Re: Active State 64-bit and Win32 Modules <bart.lateur@pandora.be>
decimal round off issue <spz1st@gmail.com>
Re: decimal round off issue <jurgenex@hotmail.com>
Re: decimal round off issue <spz1st@gmail.com>
Re: decimal round off issue sln@netherlands.com
Re: decimal round off issue <stanley@peak.org>
Re: decimal round off issue sln@netherlands.com
Re: decimal round off issue <josef.moellers@ts.fujitsu.com>
FAQ 4.62 What's the difference between "delete" and "un <brian@theperlreview.com>
FAQ 5.24 How do I randomly update a binary file? <brian@theperlreview.com>
FAQ 8.26 Why doesn't open() return an error when a pipe <brian@theperlreview.com>
Log4perl -- how to copy FATALs to STDERR <BLOCKSPAMfishfry@your-mailbox.com>
Re: Log4perl -- how to copy FATALs to STDERR <bart.lateur@pandora.be>
times() returns incorrect value? <kwatch@gmail.com>
Re: times() returns incorrect value? <matteo.corti@gmail.com>
Re: times() returns incorrect value? <kwatch@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 22 Sep 2009 09:11:12 -0700 (PDT)
From: pgodfrin <pgodfrin@gmail.com>
Subject: Active State 64-bit and Win32 Modules
Message-Id: <c844a60d-318c-4bf3-b72a-d1ba8cea4b73@j19g2000vbp.googlegroups.com>
Greetings,
Does anyone know if the Win32 modules for ActiveState Perl 64 bit are
compatible with Windows Server 2008?
phil
------------------------------
Date: Tue, 22 Sep 2009 18:42:18 +0200
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Active State 64-bit and Win32 Modules
Message-Id: <suuhb51sulicr1ogrenk3q9q546igq2jir@4ax.com>
pgodfrin wrote:
>Does anyone know if the Win32 modules for ActiveState Perl 64 bit are
>compatible with Windows Server 2008?
I don't know anything about ActivePerl 64 bit, I'm just making use of my
common sense.
I am pretty sure that you'll need 64 bit versions for your XS modules,
and not 32 bit versions. Don't worry, PPM will know to do the right
version.
And Windows 2008 Server is just Windows. There's no incompatibility to
be expected because of the Windows version.
If you need to compile your own modules, here's a usenet thread on what
you best use as a compiler:
http://groups.google.com/group/perl.beginners/browse_thread/thread/0e36ff88a16106c3/ced61e938025142d?lnk=raot
--
Bart.
------------------------------
Date: Tue, 22 Sep 2009 10:01:55 -0700 (PDT)
From: pgodfrin <pgodfrin@gmail.com>
Subject: Re: Active State 64-bit and Win32 Modules
Message-Id: <cf3c8a5e-037c-4495-9df6-839d0de1b680@p23g2000vbl.googlegroups.com>
On Sep 22, 11:42=A0am, Bart Lateur <bart.lat...@pandora.be> wrote:
> pgodfrin wrote:
> >Does anyone know if the Win32 modules for ActiveState Perl 64 bit are
> >compatible with Windows Server 2008?
>
> I don't know anything about ActivePerl 64 bit, I'm just making use of my
> common sense.
>
> I am pretty sure that you'll need 64 bit versions for your XS modules,
> and not 32 bit versions. Don't worry, PPM will know to do the right
> version.
>
> And Windows 2008 Server is just Windows. There's no incompatibility to
> be expected because of the Windows version.
>
> If you need to compile your own modules, here's a usenet thread on what
> you best use as a compiler:
>
> http://groups.google.com/group/perl.beginners/browse_thread/thread/0e...
>
> --
> =A0 =A0 =A0 =A0 Bart.
OK - it looks like there are Win32 modules (Win32:Service,
Win32::EventLog, etc) installed as part of the 64-bit package. I'm
wondering if they still function as expected in Server 2008 64-bit...
(what are XS modules?)
phil
------------------------------
Date: Tue, 22 Sep 2009 23:09:46 -0700 (PDT)
From: sisyphus <sisyphus359@gmail.com>
Subject: Re: Active State 64-bit and Win32 Modules
Message-Id: <8d1397ed-b9d9-4ad1-bb64-cf91fe9025a4@2g2000prl.googlegroups.com>
On Sep 23, 3:01=A0am, pgodfrin <pgodf...@gmail.com> wrote:
>
> OK - it looks like there are Win32 modules (Win32:Service,
> Win32::EventLog, etc) installed as part of the 64-bit package. I'm
> wondering if they still function as expected in Server 2008 64-bit...
Yes, they should function the same.
> (what are XS modules?)
The source of an XS module contains an XS file, which contains code
that needs to be compiled. You'll therefore need a C compiler to build
and install such modules.
OTOH, pure perl modules don't contain any code that needs to be
compiled. One can install them even if one doesn't have a C compiler.
Cheers,
Rob
------------------------------
Date: Wed, 23 Sep 2009 08:52:47 +0200
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Active State 64-bit and Win32 Modules
Message-Id: <79hjb555hfihv9d9jiruevi153sjfk9nf6@4ax.com>
pgodfrin wrote:
>(what are XS modules?)
Modules that are implemented as a DLL, with a bootstrap/interface layer
in Perl.
"XS" (pronounced excess; yes, it's a pun) is system of macros to write
the C interface to Perl portably.
--
Bart.
------------------------------
Date: Tue, 22 Sep 2009 10:08:55 -0700 (PDT)
From: Shiping Zhang <spz1st@gmail.com>
Subject: decimal round off issue
Message-Id: <8fa4908e-d0c4-4916-bdd9-707bf08cd533@f10g2000vbf.googlegroups.com>
Is this a bug in perl?
$v = sprintf "%.1f", 2.25;
print $v, "\n";
The above code produced 2.2
$v = sprintf "%.1f", 2.35;
print $v, "\n";
The above code produced 2.4
I tested several versions, they all behaved the same.
------------------------------
Date: Tue, 22 Sep 2009 10:34:24 -0700
From: J黵gen Exner <jurgenex@hotmail.com>
Subject: Re: decimal round off issue
Message-Id: <k52ib59i6fr8gg0god7h6jtj0urk3jgq1p@4ax.com>
Shiping Zhang <spz1st@gmail.com> wrote:
>Is this a bug in perl?
>
>$v = sprintf "%.1f", 2.25;
>print $v, "\n";
>
>The above code produced 2.2
I cannot reproduce this observation. For me it prints 2.3.
( v5.10.0 built for MSWin32-x86-multi-thread)
>$v = sprintf "%.1f", 2.35;
>print $v, "\n";
>
>The above code produced 2.4
>
>I tested several versions, they all behaved the same.
However more than likely you don't even need the sprintf() assignment
with separate print(), a simple
printf "%.1f", 2.35;
will most likely behave exactly the same.
If so then try
printf "%.40f", 2.25;
and
printf "%.40f", 2.35;
on your Perl installation. This will most likely demonstrate the reason
for your observation. For an explanation please
- see "perldoc -q 999"
- re-read your notes from "Introduction into Computer Numerics"
- check the NG archives for dozens and dozens of similar posts and the
replies to them
jue
------------------------------
Date: Tue, 22 Sep 2009 12:52:36 -0700 (PDT)
From: Shiping Zhang <spz1st@gmail.com>
Subject: Re: decimal round off issue
Message-Id: <8a268154-358f-47c1-a9e0-d0927574f25d@d21g2000vbm.googlegroups.com>
On 9=D4=C222=C8=D5, =CF=C2=CE=E71=CA=B108=B7=D6, Shiping Zhang <spz...@gmai=
l.com> wrote:
> Is this a bug in perl?
>
> $v =3D sprintf "%.1f", 2.25;
> print $v, "\n";
>
> The above code produced 2.2
>
> $v =3D sprintf "%.1f", 2.35;
> print $v, "\n";
>
> The above code produced 2.4
>
> I tested several versions, they all behaved the same.
Okay, it's not a bug. This is due to limitation of machine (binary)
representation of floating point numbers. A test C program behaved
the same.
------------------------------
Date: Tue, 22 Sep 2009 14:16:04 -0700
From: sln@netherlands.com
Subject: Re: decimal round off issue
Message-Id: <ceeib5lb7329rdbb7qkc1a9g6ldhbrk7je@4ax.com>
On Tue, 22 Sep 2009 12:52:36 -0700 (PDT), Shiping Zhang <spz1st@gmail.com> wrote:
>On 9月22日, 下午1时08分, Shiping Zhang <spz...@gmail.com> wrote:
>> Is this a bug in perl?
>>
>> $v = sprintf "%.1f", 2.25;
>> print $v, "\n";
>>
>> The above code produced 2.2
>>
>> $v = sprintf "%.1f", 2.35;
>> print $v, "\n";
>>
>> The above code produced 2.4
>>
>> I tested several versions, they all behaved the same.
>
>Okay, it's not a bug. This is due to limitation of machine (binary)
>representation of floating point numbers. A test C program behaved
>the same.
Right, a binary thing! But more than that, different results across
different floating point hardware, firmware, libs.
You would think all things being equal, the same error pattern should
be had on all machines.
The good news is that internal fp operations wash out those discrepenccies
well past the number of digits of which the real universe can actually
be measured by physical means. Ie, its not right/wrong unless you can
prove it is/isn't. There are probably wider (bit-wise) floating point
registers available for calculations on scientific principles that can't
be proven.
c:\>perl -e "for(2.15,2.25,2.35,2.45,2.55,2.65) {$v = sprintf \"%.1f\", $_;
print \"$v\n\"}"
2.1
2.3
2.4
2.5
2.5
2.6
-sln
------------------------------
Date: Tue, 22 Sep 2009 14:42:09 -0700
From: John Stanley <stanley@peak.org>
Subject: Re: decimal round off issue
Message-Id: <alpine.LRH.2.00.0909221436420.5941@shell.peak.org>
On Tue, 22 Sep 2009, Shiping Zhang wrote:
> On 9=E6=9C=8822=E6=97=A5, =E4=B8=8B=E5=8D=881=E6=97=B608=E5=88=86, Shipin=
g Zhang <spz...@gmail.com> wrote:
>> Is this a bug in perl?
>>
>> $v =3D sprintf "%.1f", 2.25;
>> print $v, "\n";
>>
>> The above code produced 2.2
>>...
> Okay, it's not a bug. This is due to limitation of machine (binary)
> representation of floating point numbers. A test C program behaved
> the same.
I don't think I missed class that day, but what binary representation of=20
floating point CANNOT represent the base ten number "2.25"? That's 10.01=20
base two.
------------------------------
Date: Tue, 22 Sep 2009 18:33:44 -0700
From: sln@netherlands.com
Subject: Re: decimal round off issue
Message-Id: <2usib593auckklfu8h8v9d5m9f55aul5ht@4ax.com>
On Tue, 22 Sep 2009 14:42:09 -0700, John Stanley <stanley@peak.org> wrote:
>
>On Tue, 22 Sep 2009, Shiping Zhang wrote:
>
>> On 9?22?, ??1?08?, Shiping Zhang <spz...@gmail.com> wrote:
>>> Is this a bug in perl?
>>>
>>> $v = sprintf "%.1f", 2.25;
>>> print $v, "\n";
>>>
>>> The above code produced 2.2
>>>...
>
>> Okay, it's not a bug. This is due to limitation of machine (binary)
>> representation of floating point numbers. A test C program behaved
>> the same.
>
>I don't think I missed class that day, but what binary representation of
>floating point CANNOT represent the base ten number "2.25"? That's 10.01
>base two.
>
Thats very true. And its non-repeating. Therefore, it should not be a
problem going from (1.001 x 2**1)base 2, to 2.25 base 10 and having it display
correctly when it comes to rounding and formatting string representation.
I'm not sure that rounding happens the same way on all systems when there is
a repeting binary fraction (like .55 base 10).
From wikipedia: http://en.wikipedia.org/wiki/IEEE_754-1985
I wonder if you do a bitwise examination of a float variable if it
will show the sign, exp, fraction bits like in the standard?
Or on the language level, are the bitwise operators restricted to
operations on integers?
Where are the calculators that do binary <-> decimal fractions?
Don't want to do it by hand all the time.
-sln
------------------------------
Date: Wed, 23 Sep 2009 09:05:58 +0200
From: Josef Moellers <josef.moellers@ts.fujitsu.com>
Subject: Re: decimal round off issue
Message-Id: <h9chcm$gfh$2@nntp.fujitsu-siemens.com>
J黵gen Exner wrote:
> Shiping Zhang <spz1st@gmail.com> wrote:
>> Is this a bug in perl?
>>
>> $v = sprintf "%.1f", 2.25;
>> print $v, "\n";
>>
>> The above code produced 2.2
>
> I cannot reproduce this observation. For me it prints 2.3.
> ( v5.10.0 built for MSWin32-x86-multi-thread)
v5.8,8 running on Kubuntu 8.04LTS has the same peculiarity:
$v = sprintf "%.1f", 2.25;
print $v, "\n";
$v = sprintf "%.1f", 2.35;
print $v, "\n";
2.2
2.4
--
These are my personal views and not those of Fujitsu Technology Solutions!
Josef M鰈lers (Pinguinpfleger bei FTS)
If failure had no penalty success would not be a prize (T. Pratchett)
Company Details: http://de.ts.fujitsu.com/imprint.html
------------------------------
Date: Tue, 22 Sep 2009 22:00:03 GMT
From: PerlFAQ Server <brian@theperlreview.com>
Subject: FAQ 4.62 What's the difference between "delete" and "undef" with hashes?
Message-Id: <DNbum.211708$0e4.144109@newsfe19.iad>
This is an excerpt from the latest version perlfaq4.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .
--------------------------------------------------------------------
4.62: What's the difference between "delete" and "undef" with hashes?
Hashes contain pairs of scalars: the first is the key, the second is the
value. The key will be coerced to a string, although the value can be
any kind of scalar: string, number, or reference. If a key $key is
present in %hash, "exists($hash{$key})" will return true. The value for
a given key can be "undef", in which case $hash{$key} will be "undef"
while "exists $hash{$key}" will return true. This corresponds to ($key,
"undef") being in the hash.
Pictures help... here's the %hash table:
keys values
+------+------+
| a | 3 |
| x | 7 |
| d | 0 |
| e | 2 |
+------+------+
And these conditions hold
$hash{'a'} is true
$hash{'d'} is false
defined $hash{'d'} is true
defined $hash{'a'} is true
exists $hash{'a'} is true (Perl 5 only)
grep ($_ eq 'a', keys %hash) is true
If you now say
undef $hash{'a'}
your table now reads:
keys values
+------+------+
| a | undef|
| x | 7 |
| d | 0 |
| e | 2 |
+------+------+
and these conditions now hold; changes in caps:
$hash{'a'} is FALSE
$hash{'d'} is false
defined $hash{'d'} is true
defined $hash{'a'} is FALSE
exists $hash{'a'} is true (Perl 5 only)
grep ($_ eq 'a', keys %hash) is true
Notice the last two: you have an undef value, but a defined key!
Now, consider this:
delete $hash{'a'}
your table now reads:
keys values
+------+------+
| x | 7 |
| d | 0 |
| e | 2 |
+------+------+
and these conditions now hold; changes in caps:
$hash{'a'} is false
$hash{'d'} is false
defined $hash{'d'} is true
defined $hash{'a'} is false
exists $hash{'a'} is FALSE (Perl 5 only)
grep ($_ eq 'a', keys %hash) is FALSE
See, the whole entry is gone!
--------------------------------------------------------------------
The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
are not necessarily experts in every domain where Perl might show up,
so please include as much information as possible and relevant in any
corrections. The perlfaq-workers also don't have access to every
operating system or platform, so please include relevant details for
corrections to examples that do not work on particular platforms.
Working code is greatly appreciated.
If you'd like to help maintain the perlfaq, see the details in
perlfaq.pod.
------------------------------
Date: Wed, 23 Sep 2009 04:00:03 GMT
From: PerlFAQ Server <brian@theperlreview.com>
Subject: FAQ 5.24 How do I randomly update a binary file?
Message-Id: <73hum.68099$u76.27685@newsfe10.iad>
This is an excerpt from the latest version perlfaq5.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .
--------------------------------------------------------------------
5.24: How do I randomly update a binary file?
If you're just trying to patch a binary, in many cases something as
simple as this works:
perl -i -pe 's{window manager}{window mangler}g' /usr/bin/emacs
However, if you have fixed sized records, then you might do something
more like this:
$RECSIZE = 220; # size of record, in bytes
$recno = 37; # which record to update
open(FH, "+<somewhere") || die "can't update somewhere: $!";
seek(FH, $recno * $RECSIZE, 0);
read(FH, $record, $RECSIZE) == $RECSIZE || die "can't read record $recno: $!";
# munge the record
seek(FH, -$RECSIZE, 1);
print FH $record;
close FH;
Locking and error checking are left as an exercise for the reader. Don't
forget them or you'll be quite sorry.
--------------------------------------------------------------------
The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
are not necessarily experts in every domain where Perl might show up,
so please include as much information as possible and relevant in any
corrections. The perlfaq-workers also don't have access to every
operating system or platform, so please include relevant details for
corrections to examples that do not work on particular platforms.
Working code is greatly appreciated.
If you'd like to help maintain the perlfaq, see the details in
perlfaq.pod.
------------------------------
Date: Tue, 22 Sep 2009 16:00:02 GMT
From: PerlFAQ Server <brian@theperlreview.com>
Subject: FAQ 8.26 Why doesn't open() return an error when a pipe open fails?
Message-Id: <6w6um.25857$j34.12665@newsfe01.iad>
This is an excerpt from the latest version perlfaq8.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .
--------------------------------------------------------------------
8.26: Why doesn't open() return an error when a pipe open fails?
If the second argument to a piped open() contains shell metacharacters,
perl fork()s, then exec()s a shell to decode the metacharacters and
eventually run the desired program. If the program couldn't be run, it's
the shell that gets the message, not Perl. All your Perl program can
find out is whether the shell itself could be successfully started. You
can still capture the shell's STDERR and check it for error messages.
See "How can I capture STDERR from an external command?" elsewhere in
this document, or use the IPC::Open3 module.
If there are no shell metacharacters in the argument of open(), Perl
runs the command directly, without using the shell, and can correctly
report whether the command started.
--------------------------------------------------------------------
The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
are not necessarily experts in every domain where Perl might show up,
so please include as much information as possible and relevant in any
corrections. The perlfaq-workers also don't have access to every
operating system or platform, so please include relevant details for
corrections to examples that do not work on particular platforms.
Working code is greatly appreciated.
If you'd like to help maintain the perlfaq, see the details in
perlfaq.pod.
------------------------------
Date: Tue, 22 Sep 2009 17:14:20 -0700
From: fishfry <BLOCKSPAMfishfry@your-mailbox.com>
Subject: Log4perl -- how to copy FATALs to STDERR
Message-Id: <BLOCKSPAMfishfry-86F70B.17142022092009@news.giganews.com>
Apologies if this is simple, I've been looking at the docs and can't
figure it out. When I get a fatal error I want log4perl to log it to
STDERR as well as the logfile. How do I do this?
------------------------------
Date: Wed, 23 Sep 2009 08:49:41 +0200
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Log4perl -- how to copy FATALs to STDERR
Message-Id: <rigjb51og4fuscdtu2tmjl5p2dh5ng1m09@4ax.com>
fishfry wrote:
>Apologies if this is simple, I've been looking at the docs and can't
>figure it out. When I get a fatal error I want log4perl to log it to
>STDERR as well as the logfile. How do I do this?
On Unix shell, they usually use `tee` for that.
In Perl, are a couple of modules with the same functionality: IO::Tee,
and File::Tee. You probably can use one of these.
Actually, I see in http://search.cpan.org/perldoc?Log::Log4perl that
IO::Tee is listed as a "related module", which probably means it is used
by Log::Log4perl... Except, I don't immediately see where, and it's not
in the log4perl FAQ.
--
Bart.
------------------------------
Date: Tue, 22 Sep 2009 05:50:51 -0700 (PDT)
From: makoto kuwata <kwatch@gmail.com>
Subject: times() returns incorrect value?
Message-Id: <0ad26f93-ac62-4fcf-9ffe-587bbf7cf7f3@x5g2000prf.googlegroups.com>
Hi,
I have a question about times() function.
times() returns user-time, but these values seems to be incorrect.
The following is an example code to show incorrect result:
bench.pl:
----------------------------------
use strict;
use Time::HiRes;
sub fib {
my ($n) = @_;
return $n <= 2 ? 1 : fib($n-2)+fib($n-1);
}
my @start_times = times();
my $start_time = Time::HiRes::time();
my $n = 35;
print "fib($n) = ", fib($n), "\n";
my @end_times = times();
my $end_time = Time::HiRes::time();
my $user_time = $end_times[0] - $start_times[0];
my $sys_time = $end_times[1] - $start_times[1];
my $real_time = $end_time - $start_time;
my $format = "*** user %4.4f, sys %4.4f, real %4.4f\n";
printf $format, $user_time, $sys_time, $real_time;
--------------------------------
output example:
--------------------------------
$ /usr/bin/perl -v | grep built
This is perl, v5.10.0 built for x86_64-linux-thread-multi
$ time /usr/bin/perl fib.pl
fib(35) = 9227465
*** user 4.2900, sys 0.0000, real 13.1078
real 0m13.126s
user 0m4.294s
sys 0m0.001s
--------------------------------
The above output shows that real time is over 13 seconds,
but user time is reported only 4.29 seconds.
(Of course, there is no other process to consume cpu.)
I compled and installed Perl 5.10 from source, but issue is not
solved.
Environment: FedoraCore 11 (x64), Macbook (Core2Duo 2.0GHz),
$ uname -a
Linux spica.local 2.6.29.4-167.fc11.x86_64 #1 SMP Wed May 27 17:27:08
EDT 2009 x86_64 x86_64 x86_64 GNU/Linux
Any suggestion?
--
regards,
makoto kuwata
------------------------------
Date: Tue, 22 Sep 2009 06:50:23 -0700 (PDT)
From: Teo <matteo.corti@gmail.com>
Subject: Re: times() returns incorrect value?
Message-Id: <b13ac138-aa7f-451f-ad4e-f16557fae52a@b18g2000vbl.googlegroups.com>
Dear Makoto,
On Sep 22, 2:50=A0pm, makoto kuwata <kwa...@gmail.com> wrote:
> I have a question about times() function.
> times() returns user-time, but these values seems to be incorrect.
> The following is an example code to show incorrect result:
>
> bench.pl:
> ----------------------------------
> use strict;
> use Time::HiRes;
>
> sub fib {
> =A0 my ($n) =3D @_;
> =A0 return $n <=3D 2 ? 1 : fib($n-2)+fib($n-1);
>
> }
>
> my @start_times =3D times();
> my $start_time =A0=3D Time::HiRes::time();
>
> my $n =3D 35;
> print "fib($n) =3D ", fib($n), "\n";
>
> my @end_times =A0 =3D times();
> my $end_time =A0 =A0=3D Time::HiRes::time();
>
> my $user_time =3D $end_times[0] - $start_times[0];
> my $sys_time =A0=3D $end_times[1] - $start_times[1];
> my $real_time =3D $end_time =A0 =A0 - $start_time;
>
> my $format =3D "*** user %4.4f, sys %4.4f, real %4.4f\n";
> printf $format, $user_time, $sys_time, $real_time;
> --------------------------------
>
> output example:
> --------------------------------
> $ /usr/bin/perl -v | grep built
> This is perl, v5.10.0 built for x86_64-linux-thread-multi
> $ time /usr/bin/perl fib.pl
> fib(35) =3D 9227465
> *** user 4.2900, sys 0.0000, real 13.1078
>
> real =A0 =A00m13.126s
> user =A0 =A00m4.294s
> sys =A0 =A0 0m0.001s
> --------------------------------
>
> The above output shows that real time is over 13 seconds,
> but user time is reported only 4.29 seconds.
> (Of course, there is no other process to consume cpu.)
> I compled and installed Perl 5.10 from source, but issue is not
> solved.
>
> Environment: FedoraCore 11 (x64), Macbook (Core2Duo 2.0GHz),
>
> $ uname -a
> Linux spica.local 2.6.29.4-167.fc11.x86_64 #1 SMP Wed May 27 17:27:08
> EDT 2009 x86_64 x86_64 x86_64 GNU/Linux
>
> Any suggestion?
In fact it is strange: on my Fedora machine I cannot reproduce the
problem:
$ time perl fib.pl
fib(35) =3D 9227465
*** user 26.2800, sys 0.0600, real 27.3968
real 0m27.430s
user 0m26.300s
sys 0m0.066s
The only difference is that you are on 64 bit platform (while I'm
still on a 32 bit one).
$ uname -a
Linux matteo.ethz.ch 2.6.30.5-43.fc11.i586 #1 SMP Thu Aug 27 21:18:54
EDT 2009 i686 i686 i386 GNU/Linux
$ /usr/bin/perl -v | grep built
This is perl, v5.10.0 built for i386-linux-thread-multi
Are you sure that no other processes are running? Did you try it in
single user mode?
I can observe the same behavior only with a high machine load (e.g.,
starting several instances of the process).
Matteo
------------------------------
Date: Tue, 22 Sep 2009 15:23:44 -0700 (PDT)
From: makoto kuwata <kwatch@gmail.com>
Subject: Re: times() returns incorrect value?
Message-Id: <b3b72830-3336-4900-b360-caf4453333e0@a39g2000pre.googlegroups.com>
Thank you, Teo.
I update FedoreCore11 Kernel and issue seems to be fixed.
It is kernel problem, not Perl problem. Oh my god.
--
regards,
makoto kuwata
On 2009-09-22, 10:50pm, Teo <matteo.co...@gmail.com> wrote:
> Dear Makoto,
>
> On Sep 22, 2:50=A0pm, makoto kuwata <kwa...@gmail.com> wrote:
>
>
>
>
>
> > I have a question about times() function.
> > times() returns user-time, but these values seems to be incorrect.
> > The following is an example code to show incorrect result:
>
> > bench.pl:
> > ----------------------------------
> > use strict;
> > use Time::HiRes;
>
> > sub fib {
> > =A0 my ($n) =3D @_;
> > =A0 return $n <=3D 2 ? 1 : fib($n-2)+fib($n-1);
>
> > }
>
> > my @start_times =3D times();
> > my $start_time =A0=3D Time::HiRes::time();
>
> > my $n =3D 35;
> > print "fib($n) =3D ", fib($n), "\n";
>
> > my @end_times =A0 =3D times();
> > my $end_time =A0 =A0=3D Time::HiRes::time();
>
> > my $user_time =3D $end_times[0] - $start_times[0];
> > my $sys_time =A0=3D $end_times[1] - $start_times[1];
> > my $real_time =3D $end_time =A0 =A0 - $start_time;
>
> > my $format =3D "*** user %4.4f, sys %4.4f, real %4.4f\n";
> > printf $format, $user_time, $sys_time, $real_time;
> > --------------------------------
>
> > output example:
> > --------------------------------
> > $ /usr/bin/perl -v | grep built
> > This is perl, v5.10.0 built for x86_64-linux-thread-multi
> > $ time /usr/bin/perl fib.pl
> > fib(35) =3D 9227465
> > *** user 4.2900, sys 0.0000, real 13.1078
>
> > real =A0 =A00m13.126s
> > user =A0 =A00m4.294s
> > sys =A0 =A0 0m0.001s
> > --------------------------------
>
> > The above output shows that real time is over 13 seconds,
> > but user time is reported only 4.29 seconds.
> > (Of course, there is no other process to consume cpu.)
> > I compled and installed Perl 5.10 from source, but issue is not
> > solved.
>
> > Environment: FedoraCore 11 (x64), Macbook (Core2Duo 2.0GHz),
>
> > $ uname -a
> > Linux spica.local 2.6.29.4-167.fc11.x86_64 #1 SMP Wed May 27 17:27:08
> > EDT 2009 x86_64 x86_64 x86_64 GNU/Linux
>
> > Any suggestion?
>
> In fact it is strange: on my Fedora machine I cannot reproduce the
> problem:
>
> $ time perl fib.pl
> fib(35) =3D 9227465
> *** user 26.2800, sys 0.0600, real 27.3968
>
> real =A0 =A00m27.430s
> user =A0 =A00m26.300s
> sys =A0 =A0 0m0.066s
>
> The only difference is that you are on 64 bit platform (while I'm
> still on a 32 bit one).
>
> $ uname -a
> Linux matteo.ethz.ch 2.6.30.5-43.fc11.i586 #1 SMP Thu Aug 27 21:18:54
> EDT 2009 i686 i686 i386 GNU/Linux
> $ /usr/bin/perl -v | grep built
> This is perl, v5.10.0 built for i386-linux-thread-multi
>
> Are you sure that no other processes are running? Did you try it in
> single user mode?
>
> I can observe the same behavior only with a high machine load (e.g.,
> starting several instances of the process).
>
> Matteo
------------------------------
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 2608
***************************************