in reply to Re^3: A locale independent sprintf?
in thread A locale independent sprintf?
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)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^5: A locale independent sprintf?
by kcott (Archbishop) on Jul 29, 2020 at 09:05 UTC | |
by swl (Parson) on Jul 29, 2020 at 12:18 UTC | |
by swl (Parson) on Jul 29, 2020 at 11:58 UTC | |
Re^5: A locale independent sprintf?
by swl (Parson) on Jul 29, 2020 at 05:11 UTC |
In Section
Seekers of Perl Wisdom