in reply to Re: If Statements and Regular Expressions
in thread If Statements and Regular Expressions
But that uses more memory. Which can be significant if you have a lot of data.
Grouping the data in a hash causes you to have 1250001 hashes, instead of just 5. Which carries a 10 Mb penalty.#!/usr/bin/perl use 5.010; use strict; use warnings; use Devel::Size qw [total_size]; my $size = 250_000; my @fields = qw [chr start end symbol strand]; my %families; my @structs = \my (%chr, %start, %end, %symbol, %strand); foreach my $key (1 .. $size) { $families{$key}{$_} = undef for @fields; $$_{$key} = undef for @structs; } my $s1 = total_size \%families; my $s2 = 0; $s2 += total_size $_ for @structs; printf "Big hash: %d Mb\n", $s1 / (1024 * 1024); printf "More hashes: %d Mb\n", $s2 / (1024 * 1024); printf "Savings: %.0f%%\n", 100 * ($s1 - $s2) / $s1; __END__ Big hash: 71 Mb More hashes: 61 Mb Savings: 14%
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: If Statements and Regular Expressions
by GrandFather (Saint) on Oct 01, 2008 at 00:27 UTC | |
by JavaFan (Canon) on Oct 01, 2008 at 00:56 UTC |