Skip to content

Commit

Permalink
update bench/insert.exs
Browse files Browse the repository at this point in the history
  • Loading branch information
ruslandoga committed Dec 29, 2023
1 parent 677cb85 commit 6f49d03
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions bench/insert.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ scheme = System.get_env("CH_SCHEME") || "http"
database = System.get_env("CH_DATABASE") || "ch_bench"

{:ok, conn} = Ch.start_link(scheme: scheme, hostname: hostname, port: port)
Ch.query!(conn, "CREATE DATABASE IF NOT EXISTS {$0:Identifier}", [database])
Ch.query!(conn, "CREATE DATABASE IF NOT EXISTS {db:Identifier}", %{"db" => database})

Ch.query!(conn, """
CREATE TABLE IF NOT EXISTS #{database}.benchmark (
Expand All @@ -18,7 +18,7 @@ CREATE TABLE IF NOT EXISTS #{database}.benchmark (
""")

types = [Ch.Types.u64(), Ch.Types.string(), Ch.Types.array(Ch.Types.u8()), Ch.Types.datetime()]
statement = "INSERT INTO #{database}.benchmark FORMAT RowBinary"
statement = "INSERT INTO #{database}.benchmark FORMAT RowBinary\n"

rows = fn count ->
Enum.map(1..count, fn i ->
Expand All @@ -32,7 +32,9 @@ Benchee.run(
%{
# "control" => fn rows -> Enum.each(rows, fn _row -> :ok end) end,
"encode" => fn rows -> RowBinary.encode_rows(rows, types) end,
"insert" => fn rows -> Ch.query!(conn, statement, rows, types: types) end,
"encode+insert" => fn rows ->
Ch.query!(conn, [statement | RowBinary.encode_rows(rows, types)])
end,
# "control stream" => fn rows -> rows |> Stream.chunk_every(60_000) |> Stream.run() end,
"encode stream" => fn rows ->
rows
Expand All @@ -46,7 +48,7 @@ Benchee.run(
|> Stream.chunk_every(60_000)
|> Stream.map(fn chunk -> RowBinary.encode_rows(chunk, types) end)

Ch.query!(conn, statement, stream, encode: false)
Ch.query!(conn, Stream.concat([statement], stream))
end
},
inputs: %{
Expand Down

0 comments on commit 6f49d03

Please sign in to comment.