Ask a Question related to PERL Modules, Design and Development.
-
Salvador Fandino #1
[ANN] Sort::Key 0.02
Hi,
I have released Sort::Key 0.02, a module for sorting objects by some key.
It's really fast, usually much faster than perl core sort function and
even than other popular methods like the Schwartzian or the GRM
transforms (and BTW, easier to use).
Comments, bug reports, etc., are welcome!
The docs follow...
NAME
Sort::Key - Perl extension for sorting objects by some key
SYNOPSIS
use Sort::Key;
@by_name = keysort { "$_->{surname} $_->{name}" } @people;
@by_age = nkeysort { $_->{age} } @people;
@by_sons = ikeysort { $_->{sons} } @people;
DESCRIPTION
Sort::Key provides a set of functions to sort object
arrays by some (calculated) key value.
Usually, it is faster and uses less memory than other
alternatives implemented around perl sort function.
EXPORT
This package exports these functions:
keysort { CALC_KEY } @array
returns the elements on @array sorted by the key
calculated applying "{ CALC_KEY }" to them.
Inside "{ CALC_KEY }", the object is available as
$_.
For example:
@a=({name=>john, surname=>smith},
{name=>paul, surname=>belvedere});
@by_name=keysort {$_->{name}} @a;
lkeysort { CALC_KEY } @array
similar to keysort but takes into account locale
configuration when comparing keys.
nkeysort { CALC_KEY } @array
similar to keysort but compares the keys numerically
instead of as strings.
ikeysort { CALC_KEY } @array
similar to keysort but automatically converts the
keys to integer values and compares them
numerically.
SEE ALSO
perl sort function
AUTHOR
Salvador Fandino, <sfandino@yahoo.com>
COPYRIGHT AND LICENSE
Copyright (C) 2005 by Salvador Fandino
This library is free software; you can redistribute it
and/or modify it under the same terms as Perl itself,
either Perl version 5.8.4 or, at your option, any later
version of Perl 5 you may have available.
Salvador Fandino Guest
-
Sort
Hi, I want to write a perl script to do something like this Abc 12.8 8 "left" 1 15.7 Def 13.8 9 "top" 0 19.7 -
Sort by id
Now I simple forum by Dreamweaver i use "repeat region" for show data in database . It show like this 1 2 3 4 but i want to show -
Sort bug
It appears that the runtime cannot sort a datagrid column when the items in the column contain a NaN or Infinity. Is there a way to override the... -
memory sort and disk sort
I check the sysprofile table and find there are 700 times disk sort, I think it is lack of sort memory. I want to turn all the disk sort into the... -
Ado sort error-Ado Sort -Relate, Compute By, or Sort operations cannot be done on column(s) whose key length is unknown or exceeds 10 KB.
Ado Sort -Relate, Compute By, or Sort operations cannot be done on column(s) whose key length is unknown or exceeds 10 KB. hi, guys i have asp... -
peter pilsl #2
Re: [ANN] Sort::Key 0.02
Salvador Fandino wrote:
a first test is impressive:>Comments, bug reports, etc., are welcome!
create 0.09837
sort1 0.638449 <- perl-sort
sort2 0.116141 <- your sort
best,
peter
#!/usr/bin/perl -w
use Time::HiRes qw(gettimeofday tv_interval);
use Sort::Key;
my $t0 = [gettimeofday];
print "create\t";
my $x;
foreach (0..20000) {
$x->{$_}=rand();
}
$elapsed = tv_interval ( $t0 );
print $elapsed,"\n";
$t0 = [gettimeofday];
print "sort1\t";
my @r1=sort {$x->{$a} <=> $x->{$b}} (0..20000);
$elapsed = tv_interval ( $t0 );
print $elapsed,"\n";
$t0 = [gettimeofday];
print "sort2\t";
my @r2=nkeysort {$x->{$_}} (0..20000);
$elapsed = tv_interval ( $t0 );
print $elapsed,"\n";
$t0 = [gettimeofday];
--
[url]http://www.goldfisch.at/know_list[/url]
peter pilsl Guest



Reply With Quote

