@@ -8,26 +8,25 @@ defmodule SQL.Repo do
88 use SQL , adapter: SQL.Adapters.Postgres
99 import Ecto.Query
1010 def sql ( ) do
11- # SQL.transaction do
12- # SQL.transaction do
11+ SQL . transaction do
12+ SQL . transaction do
1313 Enum . to_list ( ~SQL" SELECT 1" )
14- # end
15- # end
14+ end
15+ end
1616 end
1717
1818 def ecto ( ) do
19- # SQL.Repo.transaction(fn ->
20- # SQL.Repo.transaction(fn ->
19+ SQL.Repo . transaction ( fn ->
20+ SQL.Repo . transaction ( fn ->
2121 SQL.Repo . all ( select ( from ( "users" ) , [ 1 ] ) )
22- # end)
23- # end)
22+ end )
23+ end )
2424 end
2525end
2626Application . put_env ( :sql , :ecto_repos , [ SQL.Repo ] )
27- Application . put_env ( :sql , SQL.Repo , log: false , username: "postgres" , password: "postgres" , hostname: "localhost" , database: "sql_test#{ System . get_env ( "MIX_TEST_PARTITION" ) } " , pool_size: 10 , ssl: false )
27+ Application . put_env ( :sql , SQL.Repo , log: false , username: "postgres" , password: "postgres" , hostname: "localhost" , database: "sql_test#{ System . get_env ( "MIX_TEST_PARTITION" ) } " , pool_size: :erlang . system_info ( :schedulers_online ) , ssl: false )
2828SQL.Repo . __adapter__ ( ) . storage_up ( SQL.Repo . config ( ) )
2929SQL.Repo . start_link ( )
30- SQL.Pool . start_link ( % { username: "postgres" , password: "postgres" , hostname: "localhost" , database: "sql_test#{ System . get_env ( "MIX_TEST_PARTITION" ) } " , adapter: SQL.Adapters.Postgres , ssl: false } )
3130# query = "temp" |> recursive_ctes(true) |> with_cte("temp", as: ^union_all(select("temp", [t], %{n: 0, fact: 1}), ^where(select("temp", [t], [t.n+1, t.n+1*t.fact]), [t], t.n < 9))) |> select([t], [t.n])
3231# sql = ~SQL[with recursive temp (n, fact) as (select 0, 1 union all select n+1, (n+1)*fact from temp where n < 9)]
3332# result = Tuple.to_list(SQL.Lexer.lex("with recursive temp (n, fact) as (select 0, 1 union all select n+1, (n+1)*fact from temp where n < 9)"))
@@ -58,7 +57,7 @@ Benchee.run(
5857 # "runtime ecto" => fn _ -> SQL.Repo.to_sql(:all, "temp" |> recursive_ctes(true) |> with_cte("temp", as: ^union_all(select("temp", [t], %{n: 0, fact: 1}), ^where(select("temp", [t], [t.n+1, t.n+1*t.fact]), [t], t.n < 9))) |> select([t], [t.n])) end,
5958 # "comptime ecto" => fn _ -> SQL.Repo.to_sql(:all, query) end
6059 } ,
61- parallel: 50 ,
60+ parallel: 1 ,
6261 memory_time: 2 ,
6362 reduction_time: 2 ,
6463 unit_scaling: :smallest ,
0 commit comments