in reply to What is a fast way to get keys of a Berkeley DB into an array?

You should use strict and warnings. Particularly

print ( $#keys + 1 ) . "\n";
is not what you want.

Concerning you question, you're certainly hitting data pages, as you retrieving data values from database with c_get. Sorry, have no idea how to avoid this.

PS it looks like the following is slightly faster:

my $db = tie my %hash, 'BerkeleyDB::Btree', -Filename => 'data.dbm'; my @keys = keys %hash; print 0+@keys, "\n";

Replies are listed 'Best First'.
Re^2: What is a fast way to get keys of a Berkeley DB into an array?
by mab (Acolyte) on Jun 09, 2010 at 19:24 UTC
    Thanks - that gives me a 20% improvement for my single data point. I was holding out hope for an order of magnitude improvement but perhaps that isn't going to be achieved without maintaining some sort of key-only database.