Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Good point. I'll see if I can set up some benchmarking and post the results.

Update:

Running the code below under ubuntu bash under windows with LC_NUMERIC set to de_DE.iso88591 indicates that s///r is about 20% faster than y//r. Both are in the order of millions per second, though.

And as yet another update, the order does switch between runs so it's not a consistent outcome.

Results:

de_DE.iso88591 3,1 3.1 3.1 Rate y_sprintf s_sprintf sprintf y_sprintf 4646523/s -- -19% -63% s_sprintf 5721423/s 23% -- -54% sprintf 12396265/s 167% 117% --

Code:

use Benchmark qw {:all}; use 5.016; local $| = 1; use POSIX qw /locale_h/; use locale; print POSIX::setlocale(LC_NUMERIC) . "\n"; my $x; $x = sprintf "%.2g", 3.14; print "$x\n"; $x = sprintf ("%.2g", 3.14) =~ y/,/./r; print "$x\n"; $x = sprintf ("%.2g", 3.14) =~ s/,/./r; print "$x\n"; cmpthese ( -3, { sprintf => 'use strict; use warnings; my $x = sprintf ("%.2g +", 3.14)', y_sprintf => 'use strict; use warnings; my $x = sprintf ("%.2g +", 3.14) =~ y/,/./r', s_sprintf => 'use strict; use warnings; my $x = sprintf ("%.2g +", 3.14) =~ s/,/./r', } );

(post was further updated to distinguish results from code)


In reply to Re^4: A locale independent sprintf? by swl
in thread A locale independent sprintf? by swl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (3)
As of 2024-04-19 01:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found