/
benchmark.io
executable file
·70 lines (56 loc) · 1.72 KB
/
benchmark.io
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env io
recCount := if(System args at(1), System args at(1) asNumber, 50000)
c := DBI with("sqlite3")
c optionPut("dbname", "test.db")
c optionPut("sqlite3_dbdir", ".")
c connect
(" Setup: Creating table/inserting " .. recCount .. " rows") println
c execute("BEGIN TRANSACTION")
c execute("""CREATE TABLE people (first varchar(15),
last varchar(15), dob date)""")
for(a, 1, recCount,
c execute("INSERT INTO people VALUES ('John', 'Doe', '1972-10-21')")
c execute("INSERT INTO people VALUES ('Jane', 'Doe', '1933-08-12')")
c execute("INSERT INTO people VALUES ('Joe', 'Doe', '2002-03-17')")
)
c execute("COMMIT")
"Benchmark 1: Old fashioned DBI access: " print
time1 := Date cpuSecondsToRun(
a := 1
r := c query("SELECT * FROM people")
r foreach(row,
fullName := row at(1) .. " " .. row at(2)
age := Duration fromNumber(row at(3) secondsSinceNow) years
// Ensure things are working correctly
if (a == 1, (" " .. fullName .. " " .. age) println)
a := a + 1
)
r done
)
"Benchmark 2: New OO DBI access: " print
time2 := Date cpuSecondsToRun(
a := 1
r := c query("SELECT * FROM people")
r foreach(Person, p,
p fullName
p age
// Ensure things are working correctly
if (a == 1, (" " .. p fullName .. " " .. p age) println)
a := a + 1
)
r done
)
"" println
("Old fashioned DBI access: " .. time1) println
(" New OO DBI access: " .. time2) println
if(time2 > time1,
diff := time2 - time1
(" OO slower by seconds: " .. diff) println
(" per request: " .. (diff / recCount)) println,
diff := time1 - time2
(" Old slower by seconds: " .. diff) println
(" per request: " .. (diff / recCount)) println
)
"" println
c execute("DROP TABLE people")
c close