parent
e05e8b9c25
commit
b7aadf26e2
Binary file not shown.
@ -0,0 +1,60 @@ |
|||||||
|
path = "benchmarks/explorer/chain/recent_collated_transactions.benchee" |
||||||
|
|
||||||
|
import Explorer.Factory |
||||||
|
|
||||||
|
alias Explorer.{Chain, Repo} |
||||||
|
alias Explorer.Chain.Block |
||||||
|
|
||||||
|
Benchee.run( |
||||||
|
%{ |
||||||
|
"Explorer.Chain.recent_collated_transactions" => fn _ -> |
||||||
|
Chain.recent_collated_transactions() |
||||||
|
end |
||||||
|
}, |
||||||
|
inputs: %{ |
||||||
|
" 0 blocks 0 transactions per block" => %{block_count: 0, transaction_count_per_block: 0}, |
||||||
|
" 10 blocks 0 transactions per block" => %{block_count: 10, transaction_count_per_block: 0}, |
||||||
|
" 10 blocks 1 transaction per block" => %{block_count: 10, transaction_count_per_block: 1}, |
||||||
|
" 10 blocks 10 transactions per blocks" => %{block_count: 10, transaction_count_per_block: 10}, |
||||||
|
" 10 blocks 100 transactions per blocks" => %{block_count: 10, transaction_count_per_block: 100}, |
||||||
|
" 10 blocks 250 transactions per blocks" => %{block_count: 10, transaction_count_per_block: 250}, |
||||||
|
" 100 blocks 0 transactions per block" => %{block_count: 100, transaction_count_per_block: 0}, |
||||||
|
" 100 blocks 1 transaction per block" => %{block_count: 100, transaction_count_per_block: 1}, |
||||||
|
" 100 blocks 10 transactions per blocks" => %{block_count: 100, transaction_count_per_block: 10}, |
||||||
|
" 100 blocks 100 transactions per blocks" => %{block_count: 100, transaction_count_per_block: 100}, |
||||||
|
" 100 blocks 250 transactions per blocks" => %{block_count: 100, transaction_count_per_block: 250}, |
||||||
|
"1000 blocks 0 transactions per block" => %{block_count: 1000, transaction_count_per_block: 0}, |
||||||
|
"1000 blocks 1 transaction per block" => %{block_count: 1000, transaction_count_per_block: 1}, |
||||||
|
"1000 blocks 10 transactions per blocks" => %{block_count: 1000, transaction_count_per_block: 10}, |
||||||
|
"1000 blocks 100 transactions per blocks" => %{block_count: 1000, transaction_count_per_block: 100} |
||||||
|
}, |
||||||
|
before_scenario: fn %{block_count: block_count, transaction_count_per_block: transaction_count_per_block} = input -> |
||||||
|
:ok = Ecto.Adapters.SQL.Sandbox.checkout(Repo, ownership_timeout: :infinity) |
||||||
|
|
||||||
|
# ensure database is clean from failed runs |
||||||
|
0 = Repo.aggregate(Block, :count, :hash) |
||||||
|
|
||||||
|
block_count |
||||||
|
|> insert_list(:block) |
||||||
|
|> Enum.each(fn block -> |
||||||
|
transaction_count_per_block |
||||||
|
|> insert_list(:transaction) |
||||||
|
|> Enum.each(fn transaction -> |
||||||
|
transaction |
||||||
|
|> with_block(block) |
||||||
|
|> with_receipt() |
||||||
|
end) |
||||||
|
end) |
||||||
|
|
||||||
|
input |
||||||
|
end, |
||||||
|
formatter_options: %{ |
||||||
|
console: %{extended_statistics: true} |
||||||
|
}, |
||||||
|
load: path, |
||||||
|
save: [ |
||||||
|
path: path, |
||||||
|
tag: "separate-receipts" |
||||||
|
], |
||||||
|
time: 10 |
||||||
|
) |
@ -1,36 +0,0 @@ |
|||||||
defmodule ExplorerWeb.Factory do |
|
||||||
import Ecto.Query |
|
||||||
import Explorer.Factory |
|
||||||
|
|
||||||
alias Explorer.Chain.{Block, Transaction} |
|
||||||
alias Explorer.Repo |
|
||||||
|
|
||||||
def with_block(%Transaction{index: nil} = transaction, %Block{hash: block_hash}) do |
|
||||||
next_transaction_index = block_hash_to_next_transaction_index(block_hash) |
|
||||||
|
|
||||||
transaction |
|
||||||
|> Transaction.changeset(%{block_hash: block_hash, index: next_transaction_index}) |
|
||||||
|> Repo.update!() |
|
||||||
|> Repo.preload(:block) |
|
||||||
end |
|
||||||
|
|
||||||
def with_receipt(%Transaction{hash: hash, index: index} = transaction) do |
|
||||||
insert(:receipt, transaction_hash: hash, transaction_index: index) |
|
||||||
|
|
||||||
Repo.preload(transaction, :receipt) |
|
||||||
end |
|
||||||
|
|
||||||
defp block_hash_to_next_transaction_index(block_hash) do |
|
||||||
query = |
|
||||||
from( |
|
||||||
transaction in Transaction, |
|
||||||
select: transaction.index, |
|
||||||
where: transaction.block_hash == ^block_hash |
|
||||||
) |
|
||||||
|
|
||||||
case Repo.one(query) do |
|
||||||
nil -> 0 |
|
||||||
index -> index + 1 |
|
||||||
end |
|
||||||
end |
|
||||||
end |
|
Loading…
Reference in new issue