Skip to content
This repository has been archived by the owner on Oct 8, 2020. It is now read-only.

Commit

Permalink
First benchmark: Looking at Xgit.Repository.WorkingTree.ParseIndexFil…
Browse files Browse the repository at this point in the history
…e.from_iodevice/1. (#167)
  • Loading branch information
scouten committed Sep 17, 2019
1 parent 9de610f commit 549e7c4
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .formatter.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"],
inputs: ["{mix,.formatter}.exs", "{bench,config,lib,test}/**/*.{ex,exs}"],
locals_without_parens: [cover: 1]
]
31 changes: 31 additions & 0 deletions bench/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
When there's a concern about algorithmic or absolute cost of a specific implementation,
let's build a microbenchmark here. As of this writing (mid-September 2019), I think the
following functions need study.

```
Xgit.Core.DirCache
add_entries/2
fully_merged?/1
remove_entries/2
to_tree_objects/2
Xgit.Core.FilePath
check_path_segment/2
check_path/2
valid?/2
Xgit.Core.Object
valid?/1
Xgit.Core.Tree
from_object/1
to_object/1
Xgit.Repository (permute on the implementations)
get_object/2
has_all_object_ids?/2
put_loose_object/2
Xgit.Repository.WorkingTree.WriteIndexFile
to_iodevice/1
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Measure cost of Xgit.Repository.WorkingTree.ParseIndexFile.from_iodevice/1.
#
# EXPECTED: Cost is roughly O(n) on the number of items in the index file.
#
# --------------------------------------------------------------------------------------
#
# $ mix run bench/xgit/repository/working_tree/parse_index_file/from_iodevice.exs
# Operating System: macOS
# CPU Information: Intel(R) Core(TM) i7-4980HQ CPU @ 2.80GHz
# Number of Available Cores: 8
# Available memory: 16 GB
# Elixir 1.9.1
# Erlang 22.0.7
#
# Benchmark suite executing with the following configuration:
# warmup: 2 s
# time: 5 s
# memory time: 0 ns
# parallel: 1
# inputs: 10 items, 100 items, 1000 items
# Estimated total run time: 21 s
#
# Benchmarking parse_index_file with input 10 items...
# Benchmarking parse_index_file with input 100 items...
# Benchmarking parse_index_file with input 1000 items...
#
# ##### With input 10 items #####
# Name ips average deviation median 99th %
# parse_index_file 1.14 K 880.11 μs ±7.61% 871 μs 1090.70 μs
#
# ##### With input 100 items #####
# Name ips average deviation median 99th %
# parse_index_file 146.25 6.84 ms ±3.99% 6.81 ms 7.69 ms
#
# ##### With input 1000 items #####
# Name ips average deviation median 99th %
# parse_index_file 14.87 67.23 ms ±1.97% 67.01 ms 73.24 ms
#
# --------------------------------------------------------------------------------------

alias Xgit.Repository.WorkingTree.ParseIndexFile
alias Xgit.Util.TrailingHashDevice

Temp.track!()

make_index_file_with_n_entries = fn n ->
git_dir = Temp.mkdir!()

{_output, 0} = System.cmd("git", ["init"], cd: git_dir)

Enum.map(1..n, fn i ->
name = "0000#{i}"

{_output, _0} =
System.cmd(
"git",
[
"update-index",
"--add",
"--cacheinfo",
"100644",
"18832d35117ef2f013c4009f5b2128dfaeff354f",
"a#{String.slice(name, -4, 4)}"
],
cd: git_dir
)
end)

Path.join([git_dir, ".git", "index"])
end

thd_open_file! = fn path ->
{:ok, iodevice} = TrailingHashDevice.open_file(path)
iodevice
end

inputs = %{
"10 items" => make_index_file_with_n_entries.(10),
"100 items" => make_index_file_with_n_entries.(100),
"1000 items" => make_index_file_with_n_entries.(1000)
}

Benchee.run(
%{
"parse_index_file" => fn index_file_path ->
iodevice = thd_open_file!.(index_file_path)
ParseIndexFile.from_iodevice(iodevice)
File.close(iodevice)
end
},
inputs: inputs
)
3 changes: 2 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ defmodule Xgit.MixProject do

defp deps do
[
{:benchee, "~> 1.0", only: :dev},
{:con_cache, "~> 0.13"},
{:credo, "~> 1.1", only: [:dev, :test]},
{:dialyxir, "~> 1.0.0-rc.6", only: :dev, runtime: false},
{:excoveralls, "~> 0.11", only: :test},
{:ex_doc, "~> 0.21", only: :dev},
{:temp, "~> 0.4", only: :test}
{:temp, "~> 0.4", only: [:dev, :test]}
]
end

Expand Down
8 changes: 5 additions & 3 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
%{
"benchee": {:hex, :benchee, "1.0.1", "66b211f9bfd84bd97e6d1beaddf8fc2312aaabe192f776e8931cb0c16f53a521", [:mix], [{:deep_merge, "~> 1.0", [hex: :deep_merge, optional: false]}]},
"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], []},
"certifi": {:hex, :certifi, "2.5.1", "867ce347f7c7d78563450a18a6a28a8090331e77fa02380b4a21962a65d36ee5", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, optional: false]}]},
"con_cache": {:hex, :con_cache, "0.14.0", "863acb90fa08017be3129074993af944cf7a4b6c3ee7c06c5cd0ed6b94fbc223", [:mix], []},
"credo": {:hex, :credo, "1.1.4", "c2f3b73c895d81d859cec7fcee7ffdb972c595fd8e85ab6f8c2adbf01cf7c29c", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm"},
"credo": {:hex, :credo, "1.1.4", "c2f3b73c895d81d859cec7fcee7ffdb972c595fd8e85ab6f8c2adbf01cf7c29c", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, optional: false]}, {:jason, "~> 1.0", [hex: :jason, optional: false]}]},
"deep_merge": {:hex, :deep_merge, "1.0.0", "b4aa1a0d1acac393bdf38b2291af38cb1d4a52806cf7a4906f718e1feb5ee961", [:mix], []},
"dialyxir": {:hex, :dialyxir, "1.0.0-rc.6", "78e97d9c0ff1b5521dd68041193891aebebce52fc3b93463c0a6806874557d7d", [:mix], [{:erlex, "~> 0.2.1", [hex: :erlex, optional: false]}]},
"earmark": {:hex, :earmark, "1.3.6", "ce1d0675e10a5bb46b007549362bd3f5f08908843957687d8484fe7f37466b19", [:mix], [], "hexpm"},
"earmark": {:hex, :earmark, "1.3.6", "ce1d0675e10a5bb46b007549362bd3f5f08908843957687d8484fe7f37466b19", [:mix], []},
"erlex": {:hex, :erlex, "0.2.4", "23791959df45fe8f01f388c6f7eb733cc361668cbeedd801bf491c55a029917b", [:mix], []},
"ex_doc": {:hex, :ex_doc, "0.21.2", "caca5bc28ed7b3bdc0b662f8afe2bee1eedb5c3cf7b322feeeb7c6ebbde089d6", [:mix], [{:earmark, "~> 1.3.3 or ~> 1.4", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm"},
"ex_doc": {:hex, :ex_doc, "0.21.2", "caca5bc28ed7b3bdc0b662f8afe2bee1eedb5c3cf7b322feeeb7c6ebbde089d6", [:mix], [{:earmark, "~> 1.3.3 or ~> 1.4", [hex: :earmark, optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, optional: false]}]},
"excoveralls": {:hex, :excoveralls, "0.11.2", "0c6f2c8db7683b0caa9d490fb8125709c54580b4255ffa7ad35f3264b075a643", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, optional: false]}, {:jason, "~> 1.0", [hex: :jason, optional: false]}]},
"hackney": {:hex, :hackney, "1.15.1", "9f8f471c844b8ce395f7b6d8398139e26ddca9ebc171a8b91342ee15a19963f4", [:rebar3], [{:certifi, "2.5.1", [hex: :certifi, optional: false]}, {:idna, "6.0.0", [hex: :idna, optional: false]}, {:metrics, "1.0.1", [hex: :metrics, optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, optional: false]}, {:ssl_verify_fun, "1.1.4", [hex: :ssl_verify_fun, optional: false]}]},
"idna": {:hex, :idna, "6.0.0", "689c46cbcdf3524c44d5f3dde8001f364cd7608a99556d8fbd8239a5798d4c10", [:rebar3], [{:unicode_util_compat, "0.4.1", [hex: :unicode_util_compat, optional: false]}]},
Expand Down

0 comments on commit 549e7c4

Please sign in to comment.