BrowserUk,
Perhaps the following minor modifications are more to your liking:
#!/usr/bin/perl use strict; use warnings; use Time::HiRes qw/gettimeofday tv_interval/; my $items = $ARGV[0] || 100; my $str = 'a'; my %hash = map {$str++ => undef} 1 .. $items; my $at_once = int($items * .10); my ($cnt, @bot_n, %known) = (0, (), ()); my $beg = [gettimeofday]; while (1) { while (my ($key, $val) = each %hash) { next if defined $val; if (exists $known{$key}) { $hash{$key} = $known{$key}; next; } my $inserted; my ($min, $max) = (0, $#bot_n); while (1) { my $mid = $min + (($max - $min) / 2); last if ! defined $bot_n[$mid]; $key gt $bot_n[$mid] ? ($min = $mid + 1) : ($max = $mid - +1); last if $min > $max; } splice @bot_n, $min, 0, $key; pop @bot_n if @bot_n > $at_once; } last if ! @bot_n; %known = (); $known{$_} = ++$cnt for @bot_n; @bot_n = (); } my $elapsed = tv_interval($beg, [gettimeofday]); my $per = sprintf("%.7f", $elapsed / $items); print "Took $elapsed seconds for $items items ($per per item)\n"; __DATA__ C:\tmp>perl buk.pl 100 Took 0.003766 seconds for 100 items (0.0000377 per item) C:\tmp>perl buk.pl 1000 Took 0.054244 seconds for 1000 items (0.0000542 per item) C:\tmp>perl buk.pl 10000 Took 0.734375 seconds for 10000 items (0.0000734 per item) C:\tmp>perl buk.pl 100000 Took 12.515625 seconds for 100000 items (0.0001252 per item) C:\tmp>perl buk.pl 1000000 Took 394.375 seconds for 1000000 items (0.0003944 per item)

Cheers - L~R


In reply to Re^9: In-place sort with order assignment by Limbic~Region
in thread In-place sort with order assignment by BrowserUk

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.