<div dir="ltr">Hi,<div><br></div><div>been wondering why does <i>uc</i> takes almost twice the time compared to <i>lc</i>? </div><div><br></div><div>code:</div><div><br></div><div><div><i>#!/usr/bin/perl</i></div><div><i>use warnings;</i></div>
<div><i>use strict;</i></div><div><i>use Benchmark qw(cmpthese timethese :hireswallclock);</i></div><div><i>my $string = 'Phone: 054-8765434 Email: <a href="mailto:nabu@lknhy4564.com">nabu@lknhy4564.com</a> 054-3232 888-22222 abdsx';</i></div>
<div><i><br></i></div><div><i>cmpthese(</i></div><div><i> timethese(</i></div><div><i> 50_000_000,</i></div><div><i> { to_lower => sub { lc($string); },</i></div><div><i> to_upper => sub { uc($string); }</i></div>
<div><i> }</i></div><div><i> )</i></div><div><i>)</i></div></div><div><i><br></i></div><div>which results in:</div><div><div><i>Benchmark: timing 50000000 iterations of to_lower, to_upper...</i></div><div><i> to_lower: 8.45244 wallclock secs ( 8.45 usr + -0.00 sys = 8.45 CPU) @ 5917159.76/s (n=50000000)</i></div>
<div><i> to_upper: 15.321 wallclock secs (15.31 usr + 0.00 sys = 15.31 CPU) @ 3265839.32/s (n=50000000)</i></div><div><i> Rate to_upper to_lower</i></div><div><i>to_upper 3265839/s -- -45%</i></div>
<div><i>to_lower 5917160/s 81% </i></div></div></div>