Acme-CPANModules-OrderedHash
view release on metacpan or search on metacpan
NAME
Acme::CPANModules::OrderedHash - List of modules that provide ordered
hash data type
VERSION
This document describes version 0.004 of Acme::CPANModules::OrderedHash
(from Perl distribution Acme-CPANModules-OrderedHash), released on
2025-04-15.
SYNOPSIS
To run benchmark with default option:
% bencher --cpanmodules-module OrderedHash
To run module startup overhead benchmark:
% bencher --module-startup --cpanmodules-module OrderedHash
For more options (dump scenario, list/include/exclude/add participants,
list/include/exclude/add datasets, etc), see bencher or run "bencher
--help".
DESCRIPTION
When you ask a Perl's hash for the list of keys, the answer comes back
unordered. In fact, Perl explicitly randomizes the order of keys it
returns everytime. The random ordering is a (security) feature, not a
bug. However, sometimes you want to know the order of insertion. These
modules provide you with an ordered hash; most of them implement it by
recording the order of insertion of keys in an additional array.
Other related modules:
Tie::SortHash - will automatically sort keys when you call keys(),
values(), each(). But this module does not maintain insertion order.
ACME::CPANMODULES ENTRIES
Tie::IxHash
Hash::Ordered
Tie::Hash::Indexed
Provides two interfaces: tied hash and OO.
Tie::LLHash
Tie::StoredOrderHash
Array::OrdHash
Provide something closest to PHP's associative array, where you can
refer elements by key or by numeric index, and insertion order is
remembered.
List::Unique::DeterministicOrder
Provide a list, not hash.
Tree::RB::XS
Multi-purpose tree data structure which can record insertion order
and act as an ordered hash. Use "track_recent => 1,
keys_in_recent_order => 1" options. Can be used as a tied hash, or
as an object (faster).
BENCHMARKED MODULES
Version numbers shown below are the versions used when running the
sample benchmark.
Tie::IxHash 1.23
Hash::Ordered 0.014
Tie::Hash::Indexed 0.08
Tie::LLHash 1.004
Tie::StoredOrderHash 0.22
Array::OrdHash 1.03
Tree::RB::XS 0.19
BENCHMARK PARTICIPANTS
* Tie::IxHash (perl_code)
Tie::IxHash
* Hash::Ordered (perl_code)
Hash::Ordered
* Tie::Hash::Indexed (perl_code)
Tie::Hash::Indexed
* Tie::LLHash (perl_code)
Tie::LLHash
* Tie::StoredOrderHash (perl_code)
Tie::StoredOrderHash
* Array::OrdHash (perl_code)
Array::OrdHash
* Tree::RB::XS (perl_code)
Tree::RB::XS
BENCHMARK DATASETS
* insert 1000 pairs
* insert 1000 pairs + delete
* insert 1000 pairs + return keys 100 times
* insert 1000 pairs + iterate 10 times
BENCHMARK SAMPLE RESULTS
Sample benchmark #1
Run on: perl: *v5.40.1*, CPU: *AMD Ryzen 5 7535HS with Radeon Graphics
(6 cores)*, OS: *GNU/Linux Ubuntu version 24.10*, OS kernel: *Linux
version 6.11.0-8-generic*.
Benchmark command (default options):
% bencher --cpanmodules-module OrderedHash
Result formatted as table (split, part 1 of 4):
#table1#
{dataset=>"insert 1000 pairs"}
+----------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
| participant | rate (/s) | time (ms) | pct_faster_vs_slowest | pct_slower_vs_fastest | errors | samples |
+----------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
| Tie::StoredOrderHash | 539 | 1.85 | 0.00% | 528.45% | 1.4e-06 | 22 |
| Tie::LLHash | 640 | 1.6 | 19.19% | 427.28% | 3.4e-06 | 20 |
| Array::OrdHash | 889 | 1.12 | 64.84% | 281.24% | 9.6e-07 | 20 |
| Tie::IxHash | 1080 | 0.928 | 99.73% | 214.65% | 6.1e-07 | 20 |
| Hash::Ordered | 1460 | 0.684 | 170.98% | 131.92% | 4.1e-07 | 20 |
| Tie::Hash::Indexed | 1600 | 0.62 | 196.91% | 111.67% | 9.6e-07 | 20 |
| Tree::RB::XS | 3400 | 0.3 | 528.45% | 0.00% | 5.4e-07 | 21 |
+----------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
The above result formatted in Benchmark.pm style:
Rate T:S T:L A:O T:I H:O TH:I TR:X
T:S 539/s -- -13% -39% -49% -63% -66% -83%
T:L 640/s 15% -- -29% -42% -57% -61% -81%
A:O 889/s 65% 42% -- -17% -38% -44% -73%
T:I 1080/s 99% 72% 20% -- -26% -33% -67%
H:O 1460/s 170% 133% 63% 35% -- -9% -56%
TH:I 1600/s 198% 158% 80% 49% 10% -- -51%
TR:X 3400/s 516% 433% 273% 209% 128% 106% --
Legends:
A:O: participant=Array::OrdHash
H:O: participant=Hash::Ordered
T:I: participant=Tie::IxHash
T:L: participant=Tie::LLHash
T:S: participant=Tie::StoredOrderHash
TH:I: participant=Tie::Hash::Indexed
TR:X: participant=Tree::RB::XS
The above result presented as chart:
Result formatted as table (split, part 2 of 4):
#table2#
{dataset=>"insert 1000 pairs + delete"}
+----------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
| participant | rate (/s) | time (ms) | pct_faster_vs_slowest | pct_slower_vs_fastest | errors | samples |
+----------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
| Tie::IxHash | 31 | 32 | 0.00% | 5838.76% | 4.8e-05 | 21 |
| Tie::StoredOrderHash | 310 | 3.3 | 875.00% | 509.10% | 8.6e-06 | 21 |
| Tie::LLHash | 376 | 2.66 | 1098.31% | 395.59% | 2.5e-06 | 20 |
| Array::OrdHash | 440 | 2.3 | 1289.81% | 327.31% | 6.1e-06 | 20 |
| Hash::Ordered | 610 | 1.6 | 1854.01% | 203.93% | 1.9e-06 | 20 |
| Tie::Hash::Indexed | 1060 | 0.946 | 3272.21% | 76.11% | 5.7e-07 | 20 |
| Tree::RB::XS | 1900 | 0.54 | 5838.76% | 0.00% | 6.3e-07 | 20 |
+----------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
The above result formatted in Benchmark.pm style:
Rate T:I T:S T:L A:O H:O TH:I TR:X
( run in 0.866 second using v1.01-cache-2.11-cpan-39bf76dae61 )