forked from elixir-sqlite/exqlite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9f1558d
commit 0b169f9
Showing
33 changed files
with
1,613 additions
and
3,104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
[ | ||
inputs: [ | ||
"{mix,.formatter}.exs", | ||
"{config,lib,test}/**/*.{ex,exs}" | ||
"{config,bench,lib,test}/**/*.{ex,exs}" | ||
], | ||
line_length: 88 | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{:ok, db} = Exqlite.open(":memory:", [:readwrite, :nomutex]) | ||
{:ok, stmt} = Exqlite.prepare(db, "select ? + 1") | ||
|
||
Benchee.run(%{ | ||
"bind_all" => fn -> Exqlite.bind_all(db, stmt, [1]) end, | ||
"dirty_cpu_bind_all" => fn -> Exqlite.dirty_cpu_bind_all(db, stmt, [1]) end | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{:ok, db} = Exqlite.open(":memory:", [:readwrite]) | ||
:ok = Exqlite.execute(db, "create table test (id integer primary key, name text)") | ||
{:ok, stmt} = Exqlite.prepare(db, "insert into test(name) values(?)") | ||
|
||
Benchee.run( | ||
%{ | ||
"insert_all" => | ||
{fn rows -> Exqlite.insert_all(db, stmt, rows) end, | ||
before_scenario: fn _input -> Exqlite.execute(db, "truncate test") end} | ||
}, | ||
inputs: %{ | ||
"3 rows" => Enum.map(1..3, fn i -> ["name-#{i}"] end), | ||
"30 rows" => Enum.map(1..30, fn i -> ["name-#{i}"] end), | ||
"90 rows" => Enum.map(1..90, fn i -> ["name-#{i}"] end), | ||
"300 rows" => Enum.map(1..300, fn i -> ["name-#{i}"] end), | ||
"1000 rows" => Enum.map(1..1000, fn i -> ["name-#{i}"] end) | ||
} | ||
) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
tmp_dir = Path.expand(Path.join("./tmp", "bench/step")) | ||
File.mkdir_p!(tmp_dir) | ||
|
||
path = Path.join(tmp_dir, "db.sqlite") | ||
if File.exists?(path), do: File.rm!(path) | ||
|
||
IO.puts("Creating DB at #{path} ...") | ||
{:ok, db} = Exqlite.open(path, [:readwrite, :nomutex, :create]) | ||
|
||
IO.puts("Inserting 1000 rows ...") | ||
:ok = Exqlite.execute(db, "create table test(stuff text)") | ||
{:ok, insert} = Exqlite.prepare(db, "insert into test(stuff) values(?)") | ||
:ok = Exqlite.insert_all(db, insert, Enum.map(1..1000, fn i -> ["name-#{i}"] end)) | ||
:ok = Exqlite.finalize(insert) | ||
|
||
select = fn limit -> | ||
{:ok, select} = Exqlite.prepare(db, "select * from test limit #{limit}") | ||
select | ||
end | ||
|
||
defmodule Bench do | ||
def step_all(db, stmt) do | ||
case Exqlite.step(db, stmt) do | ||
{:row, _} -> step_all(db, stmt) | ||
:done -> :ok | ||
end | ||
end | ||
|
||
def dirty_io_step_all(db, stmt) do | ||
case Exqlite.dirty_io_step(db, stmt) do | ||
{:row, _} -> dirty_io_step_all(db, stmt) | ||
:done -> :ok | ||
end | ||
end | ||
|
||
def multi_step_all(db, stmt, steps) do | ||
case Exqlite.multi_step(db, stmt, steps) do | ||
{:rows, _} -> multi_step_all(db, stmt, steps) | ||
{:done, _} -> :ok | ||
end | ||
end | ||
end | ||
|
||
IO.puts("Running benchmarks ...\n") | ||
|
||
Benchee.run( | ||
%{ | ||
"step" => fn stmt -> Bench.step_all(db, stmt) end, | ||
"dirty_io_step" => fn stmt -> Bench.dirty_io_step_all(db, stmt) end, | ||
"multi_step(100)" => fn stmt -> Bench.multi_step_all(db, stmt, _steps = 100) end | ||
}, | ||
inputs: %{ | ||
"10 rows" => select.(10), | ||
"100 rows" => select.(100), | ||
"500 rows" => select.(500) | ||
}, | ||
memory_time: 2 | ||
) |
Oops, something went wrong.