As per update, fixed the bug in solution_1, with little modification to performance improvement. Regarding the contention that baseline and solution_1 are doing fewer prints, of course they are. If IO is a bottle neck, then a method that can reduce calls to IO is a better method. But, if you want to eliminate those benefits of the algorithms, benchmarking with subroutines including lines like
print OUT "$_\n" foreach @list;
result in the following comparisons, where _pr specifies a version with more print statements:
Benchmark: timing 100000 iterations of Baseline, Baseline_pr, Queue, Q
+ueue_pr...
Baseline: 1.62739 wallclock secs ( 1.62 usr + 0.01 sys = 1.63 CPU)
+ @ 61349.69/s (n=100000)
Baseline_pr: 2.13879 wallclock secs ( 2.14 usr + 0.00 sys = 2.14 CPU
+) @ 46728.97/s (n=100000)
Queue: 3.61375 wallclock secs ( 3.61 usr + 0.00 sys = 3.61 CPU)
+ @ 27700.83/s (n=100000)
Queue_pr: 3.70646 wallclock secs ( 3.71 usr + 0.00 sys = 3.71 CPU)
+ @ 26954.18/s (n=100000)
Rate Queue_pr Queue Baseline_pr Baseline
Queue_pr 26954/s -- -3% -42% -56%
Queue 27701/s 3% -- -41% -55%
Baseline_pr 46729/s 73% 69% -- -24%
Baseline 61350/s 128% 121% 31% --
Benchmark: timing 1000 iterations of Baseline, Baseline_pr, Queue, Que
+ue_pr...
Baseline: 5.63275 wallclock secs ( 5.60 usr + 0.03 sys = 5.63 CPU)
+ @ 177.62/s (n=1000)
Baseline_pr: 8.3455 wallclock secs ( 8.32 usr + 0.02 sys = 8.34 CPU)
+ @ 119.90/s (n=1000)
Queue: 25.3093 wallclock secs (25.29 usr + 0.01 sys = 25.30 CPU)
+ @ 39.53/s (n=1000)
Queue_pr: 25.1902 wallclock secs (25.17 usr + 0.02 sys = 25.19 CPU)
+ @ 39.70/s (n=1000)
Rate Queue Queue_pr Baseline_pr Baseline
Queue 39.5/s -- -0% -67% -78%
Queue_pr 39.7/s 0% -- -67% -78%
Baseline_pr 120/s 203% 202% -- -32%
Baseline 178/s 349% 347% 48% --
-
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.
|