File: big_result.pl

package info (click to toggle)
libdbd-odbc-perl 1.50-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,392 kB
  • ctags: 496
  • sloc: perl: 8,818; ansic: 6,376; makefile: 33; sql: 8
file content (43 lines) | stat: -rw-r--r-- 1,019 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# $Id$
# create a table with lots of big rows and see how long it takes to
# get it back
# run once with any command line argument (to create and populate the table)
# then later without the argument
use DBI;
use strict;
use warnings;
use Benchmark::Timer;
use Data::Dumper;

my $t = Benchmark::Timer->new;
$t->start('main');
my $h = DBI->connect;

if ($ARGV[0]) {
    print "Recreating table\n";
    eval {$h->do(q/drop table mje/);};
    $h->do(q/create table mje (a varchar(50), b varchar(50), c varchar(50), d varchar(50))/);

    $h->begin_work;
    my $s = $h->prepare(q/insert into mje values(?,?,?,?)/);
    my $a = 'a' x 50;
    my $b = 'b' x 50;
    my $c = 'c' x 50;
    my $d = 'd' x 50;
    foreach (1..50000) {
        $s->execute($a, $b, $c, $d);
    }
    $h->commit;
}
$t->stop('main');

$t->start('fetch');
my $r = $h->selectall_arrayref(q/select * from mje/);
$t->stop('fetch');

#$t->start('dump');
#print Dumper($r);
#$t->stop('dump');

print "Rows fetched:", scalar(@$r), "\n";
print $t->reports;