Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Benchmark cmpthese() removing '.' char from input param

by stevieb (Canon)
on Mar 12, 2016 at 15:51 UTC ( #1157557=perlquestion: print w/replies, xml ) Need Help??

stevieb has asked for the wisdom of the Perl Monks concerning the following question:

While doing a benchmark between a C implementation of some file work to a pure Perl implementation, I found what I think might be an issue in Benchmark cmpthese, whereby it seems to remove a . character from input param to the subs being tested.

Here's an extremely minimalistic version that demonstrates the issue:

use warnings; use strict; use Benchmark qw(:all); my $fname = 'a.txt'; cmpthese( 1, { p_read => "p_read($fname)", }); sub p_read { my $fname = shift; print "$fname\n"; } __END__ atxt # cmpthese output redacted

This happens with Benchmark v1.12 on perl v5.14.4 and Benchmark v1.2 on perl v5.22.1.

Have I overlooked something in the docs perhaps that anyone knows about?

Replies are listed 'Best First'.
Re: Benchmark cmpthese() removing '.' char from input param
by dave_the_m (Monsignor) on Mar 12, 2016 at 16:10 UTC
    The code gets evalled, so you need quotes:
    p_read => "p_read('$fname')",
    Otherwise you get the bareword 'a' concatenated with the bareword 'txt'.

    Dave.

      D'oh! Of course :) Thanks guys!

      -stevieb

Re: Benchmark cmpthese() removing '.' char from input param
by 1nickt (Abbot) on Mar 12, 2016 at 16:07 UTC

    Hi stevieb, that's odd!

    Same results here on 5.22 and 5.8.8 under darwin. It seems to be an issue with variable interpolation by Benchmark:

    use strict; use warnings; use Benchmark qw(:all); cmpthese( 1, { p_read => "p_read('a.txt')", }); sub p_read { my $fname = shift; print "$fname\n"; } __END__
    Output:
    a.txt ...

    The way forward always starts with a minimal test.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1157557]
Approved by Athanasius
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2022-01-19 17:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (55 votes). Check out past polls.

    Notices?