merge performance branch into main
[scpubgit/stemmatology.git] / t / bin / update-load-test.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use lib 'lib';
7
8 use File::Temp;
9
10 use Text::Tradition;
11 use Text::Tradition::Directory;
12
13 ## We're loading the besoin data, and dumping the backend db rows into
14 ## a .sql file for load testing (testing of data loading, not the
15 ## other sort)
16 my $sql = 't/data/speed_test_load.sql';
17 my $uuid = 'load-test';
18
19 print "Loading t/data/besoin.xml and storing it in $sql ...\n";
20
21 ## Load tradition data:
22 my $tradition = Text::Tradition->new(
23    'input' => 'Self',
24    'file'  => "t/data/besoin.xml"
25 );
26 $tradition->add_stemma(dotfile => "t/data/besoin.dot");
27
28 ## save to db:
29 my $fh = File::Temp->new();
30 my $file = $fh->filename;
31 $fh->close;
32
33 my $dsn = "dbi:SQLite:$file";
34 my $dir = Text::Tradition::Directory->new(
35     dsn => $dsn,
36     extra_args => { create => 1 },
37 );
38 my $scope = $dir->new_scope;
39 $dir->store($uuid, $tradition);
40
41 ## out to SQL file:
42 `sqlite3 $file ".dump" > $sql`;
43
44 print "$sql updated,\n";
45
46 =head1 NAME
47
48 update-load-test.pl - Recreate the test file using for testing the speed of loading Traditions from a KiokuDB.
49
50 =head1 USAGE
51
52     perl t/bin/update-load-test.pl
53
54 This small script exists to enable an update of the test data for the
55 speed tests in F<t/data/load-save-speed.t>. It loads the
56 F<t/data/besoin.xml> test file and outputs the resulting database to
57 F<t/data/speed_test_load.sql>.
58
59 Only run this script after changes have been made to the way
60 Traditions data is stored in the database.
61
62