Skip to content

Instantly share code, notes, and snippets.

@obmarg
Created July 13, 2015 23:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save obmarg/84c7915872d8f63654d4 to your computer and use it in GitHub Desktop.
Save obmarg/84c7915872d8f63654d4 to your computer and use it in GitHub Desktop.
Sqlitex Stored Statement vs Query
defmodule WriteManyBench do
use Benchfella
bench "write many with query" do
{:ok, db} = Sqlitex.open(":memory:")
Sqlitex.query(db, "CREATE table x(a INTEGER PRIMARY KEY, b);")
Enum.map 1..1000, fn (i) ->
Sqlitex.query(db, "INSERT INTO x (b) VALUES (?1);", bind: [i])
end
end
bench "write many with prepared statement" do
{:ok, db} = Sqlitex.open(":memory:")
Sqlitex.query(db, "CREATE table x(a INTEGER PRIMARY KEY, b);")
statement = Sqlitex.Statement.prepare!(db, "INSERT INTO x (b) VALUES (?1);")
Enum.map 1..1000, fn (i) ->
Sqlitex.Statement.bind_values!(statement, [i])
|> Sqlitex.Statement.fetch_all
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment