Skip to content

Commit

Permalink
Add basic line encoder benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
mneudert committed May 6, 2019
1 parent 7f9578e commit e548dd8
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .credo.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
%{
name: "default",
files: %{
included: ["config/", "lib/", "test/"]
included: ["bench/", "config/", "lib/", "test/"]
}
}
]
Expand Down
2 changes: 1 addition & 1 deletion .formatter.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export_locals_without_parens = [

[
inputs: [
"{config,lib,test}/**/*.{ex,exs}",
"{bench,config,lib,test}/**/*.{ex,exs}",
"{.credo,.formatter,mix}.exs"
],
locals_without_parens: export_locals_without_parens,
Expand Down
52 changes: 52 additions & 0 deletions bench/line_encoder.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
defmodule Instream.Benchmark.LineEncoder do
alias Instream.Encoder.Line

@point_complete %{
measurement: "disk_free",
fields: %{
value: 442_221_834_240
},
tags: %{
hostname: "server01"
},
timestamp: 1_435_362_189_575_692_182
}

@point_escaping %{
measurement: ~S|"measurement with quotes"|,
tags: %{
"tag key with spaces" => ~S|tag,value,with"commas"|
},
fields: %{
~S|field_key\\\\| => ~S|string field value, only " need be quoted|
},
timestamp: nil
}
@point_simple %{
measurement: "disk_free",
fields: %{
value: 442_221_834_240
},
timestamp: nil
}
def run do
Benchee.run(
%{
"Encoding" => &Line.encode/1
},
inputs: %{
"complete" => [@point_complete],
"escaping" => [@point_escaping],
"multiple" => List.duplicate(@point_simple, 50),
"simple" => [@point_simple]
},
formatters: [{Benchee.Formatters.Console, comparison: false}],
warmup: 2,
time: 10
)
end
end

Instream.Benchmark.LineEncoder.run()
9 changes: 9 additions & 0 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ defmodule Instream.Mixfile do
name: "Instream",
version: "1.0.0-dev",
elixir: "~> 1.5",
aliases: aliases(),
deps: deps(),
description: "InfluxDB driver for Elixir",
dialyzer: dialyzer(),
docs: docs(),
elixirc_paths: elixirc_paths(Mix.env()),
package: package(),
preferred_cli_env: [
"bench.line_encoder": :bench,
coveralls: :test,
"coveralls.detail": :test,
"coveralls.travis": :test
Expand All @@ -31,8 +33,15 @@ defmodule Instream.Mixfile do
]
end

defp aliases do
[
"bench.line_encoder": ["run bench/line_encoder.exs"]
]
end

defp deps do
[
{:benchee, "~> 1.0", only: :bench, runtime: false},
{:credo, "~> 1.0", only: :dev, runtime: false},
{:dialyxir, "~> 1.0.0-rc", only: :dev, runtime: false},
{:ex_doc, ">= 0.0.0", only: :dev, runtime: false},
Expand Down
2 changes: 2 additions & 0 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
%{
"benchee": {:hex, :benchee, "1.0.1", "66b211f9bfd84bd97e6d1beaddf8fc2312aaabe192f776e8931cb0c16f53a521", [:mix], [{:deep_merge, "~> 1.0", [hex: :deep_merge, repo: "hexpm", optional: false]}], "hexpm"},
"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm"},
"certifi": {:hex, :certifi, "2.5.1", "867ce347f7c7d78563450a18a6a28a8090331e77fa02380b4a21962a65d36ee5", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm"},
"credo": {:hex, :credo, "1.0.4", "d2214d4cc88c07f54004ffd5a2a27408208841be5eca9f5a72ce9e8e835f7ede", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm"},
"deep_merge": {:hex, :deep_merge, "1.0.0", "b4aa1a0d1acac393bdf38b2291af38cb1d4a52806cf7a4906f718e1feb5ee961", [:mix], [], "hexpm"},
"dialyxir": {:hex, :dialyxir, "1.0.0-rc.6", "78e97d9c0ff1b5521dd68041193891aebebce52fc3b93463c0a6806874557d7d", [:mix], [{:erlex, "~> 0.2.1", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm"},
"earmark": {:hex, :earmark, "1.3.2", "b840562ea3d67795ffbb5bd88940b1bed0ed9fa32834915125ea7d02e35888a5", [:mix], [], "hexpm"},
"erlex": {:hex, :erlex, "0.2.1", "cee02918660807cbba9a7229cae9b42d1c6143b768c781fa6cee1eaf03ad860b", [:mix], [], "hexpm"},
Expand Down

0 comments on commit e548dd8

Please sign in to comment.