my $sth = $sth->prepare ("select field from table");
$sth->execute;
$href = $sth->fetchrow_hashref; # slowest
@arr = $sth->fetchrow_array;
$aref = $sth->fetchrow_arrayref;
my $field;
$sth->bind_columns (\$field);
$sth->fetch; # fastest
####
my $sth = prepex (
"select field1, field2",
\($field1, $field2),
"from table");
while ($sth->fetch) {
:
}
##
##
UNIFY
============== Benchmarks (2500 records)
Benchmark: running array, arrayref, bindcol, hashref, each for at least 30 CPU seconds...
hashref: 41 wallclock secs (39.26 usr + 0.01 sys = 39.27 CPU) @ 1.81/s (n= 71)
array: 35 wallclock secs (33.68 usr + 0.01 sys = 33.69 CPU) @ 2.29/s (n= 77) 26.52 %
arrayref: 34 wallclock secs (33.31 usr + 0.01 sys = 33.32 CPU) @ 2.49/s (n= 83) 8.73 % 37.57 %
bindcol: 34 wallclock secs (33.28 usr + 0.01 sys = 33.29 CPU) @ 2.58/s (n= 86) 3.61 % 42.54 %
============== Benchmarks (~ 200 000 records) [8 fields]
Benchmark: timing 5 iterations of array, arrayref, bindcol, hashref...
hashref: 188 wallclock secs (183.68 usr + 0.47 sys = 184.15 CPU) 5155.63 rec/s
array: 140 wallclock secs (133.01 usr + 0.53 sys = 133.54 CPU) 7109.56 rec/s 37.90 %
arrayref: 127 wallclock secs (124.30 usr + 0.44 sys = 124.74 CPU) 7611.11 rec/s 7.05 % 47.63 %
bindcol: 125 wallclock secs (122.22 usr + 0.49 sys = 122.71 CPU) 7737.02 rec/s 1.65 % 50.07 %
============== Benchmarks (~ 200 000 records) [1 field]
Benchmark: timing 5 iterations of array, arrayref, bindcol, hashref...
hashref: 113 wallclock secs (108.99 usr + 0.48 sys = 109.47 CPU) 8672.79 rec/s
array: 76 wallclock secs ( 73.85 usr + 0.47 sys = 74.32 CPU) 12774.60 rec/s 47.30 %
arrayref: 73 wallclock secs ( 70.89 usr + 0.42 sys = 71.31 CPU) 13313.80 rec/s 4.22 % 53.51 %
bindcol: 69 wallclock secs ( 67.44 usr + 0.47 sys = 67.91 CPU) 13980.40 rec/s 5.01 % 61.20 %