-
Notifications
You must be signed in to change notification settings - Fork 51
drop db_connection #273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
drop db_connection #273
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.