in reply to Re: Make $^V and "my" implicit
in thread Make $^V and "my" implicit
Bad benchmarks do not a good case make:
#! perl -slw use strict; use Benchmark qw[ cmpthese ]; our $fred = 'fred'; our $bill = undef; cmpthese -1, { definedor => q[ for( 1 .. 1e3 ) { $fred //= 'fred'; $bill //= 'bill';; } ], unlessdefined => q[ for( 1 .. 1e3 ) { $fred = 'fred' unless defined $fred; $bill = 'bill' unless defined $bill; } ], ternary => q[ for( 1 .. 1e3 ) { $fred = defined $fred ? $fred : 'fred'; $bill = defined $bill ? $bill : 'bill'; } ], }; __END__ C:\test>junk71 Rate ternary unlessdefined definedor ternary 3989/s -- -45% -53% unlessdefined 7283/s 83% -- -14% definedor 8455/s 112% 16% --
But as tux says, it's not about speed, it's about convenience, conciseness and readability.
Performance gain (when measured correctly), is simply a nice side effect.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Make $^V and "my" implicit
by boftx (Deacon) on Feb 04, 2014 at 01:22 UTC |