Skip to content

Instantly share code, notes, and snippets.

View PragTob's full-sized avatar

Tobias Pfeiffer PragTob

View GitHub Profile
tobi@speedy:~/github/elixir_boards_benchmark(master)$ mix run benchmark.exs
================= Getting and setting full board ====================
Operating System: Linux
CPU Information: Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz
Number of Available Cores: 8
Available memory: 15.61 GB
Elixir 1.8.2
@PragTob
PragTob / board.ex
Created June 16, 2019 15:40
Board behaviour
defmodule Board do
# can't be more specific witht types as each implementation has its own representation
@type board :: any
@type field :: any
@callback new() :: board
@callback get(board, non_neg_integer, non_neg_integer) :: field
@callback set(board, non_neg_integer, non_neg_integer, field) :: board
end
@PragTob
PragTob / task.ex
Last active April 24, 2019 09:18
Simple elxir task
pick_up_task = Task.async(fn -> geocode(pick_up_address) end)
drop_off_task = Task.async(fn -> geocode(drop_off_address) end)
geocoded_addresses = Enum.map([pick_up_task, drop_off_task], fn task -> Task.await(task) end)
@PragTob
PragTob / output.txt
Created April 8, 2019 08:50
benchee 1.0 revisiting TCO
Operating System: Linux
CPU Information: Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz
Number of Available Cores: 8
Available memory: 15.61 GB
Elixir 1.8.1
Erlang 21.3.2
Benchmark suite executing with the following configuration:
warmup: 2 s
time: 5 s
@PragTob
PragTob / bench.exs
Last active April 8, 2019 12:28
benchee 1.0 revisiting TCO
map_fun = fn i -> i + 1 end
inputs = [
{"Small (10 Thousand)", Enum.to_list(1..10_000)},
{"Middle (100 Thousand)", Enum.to_list(1..100_000)},
{"Big (1 Million)", Enum.to_list(1..1_000_000)},
{"Bigger (5 Million)", Enum.to_list(1..5_000_000)},
{"Giant (25 Million)", Enum.to_list(1..25_000_000)}
]
@PragTob
PragTob / timer.erl
Created February 10, 2019 18:01
erlang timer.tc implementation
tc(F) ->
T1 = erlang:monotonic_time(),
Val = F(),
T2 = erlang:monotonic_time(),
Time = erlang:convert_time_unit(T2 - T1, native, microsecond),
{Time, Val}.
@PragTob
PragTob / fast.exs
Created February 10, 2019 17:48
Benchmarking very fast functions with benchee
range = 1..10
integer1 = :rand.uniform(100)
integer2 = :rand.uniform(100)
Benchee.run(
%{
"Integer addition (wrong)" => fn -> 1 + 1 end,
"Integer addition" => fn -> integer1 + integer2 end,
"String concatention (wrong)" => fn -> "1" <> "1" end,
"adding a head to an array (wrong)" => fn -> [1 | [1]] end,
@PragTob
PragTob / new_formatter_options.exs
Created February 10, 2019 17:37
New formatter options
Benchee.run(
%{
"function" => fn -> something end
},
formatters: [
{Benchee.Formatters.HTML, file: "output/my.html", auto_open: false, inline_assets: true},
Benchee.Formatters.Console
]
)
@PragTob
PragTob / benchee.exs
Last active February 10, 2019 18:25
Old Benchee formatter options
Benchee.run(
%{
"function" => fn -> something end
},
formatters: [
Benchee.Formatters.HTML,
Benchee.Formatters.Console
],
formatter_options: [
html: [file: "output/my.html", auto_open: false, inline_assets: true]
@PragTob
PragTob / vodafone_wifi_ping
Last active November 24, 2018 17:55
Vodafone wifi ping
tobi@liefy:~$ ping 192.168.0.1
PING 192.168.0.1 (192.168.0.1) 56(84) bytes of data.
64 bytes from 192.168.0.1: icmp_seq=1 ttl=64 time=7.46 ms
64 bytes from 192.168.0.1: icmp_seq=2 ttl=64 time=4.83 ms
64 bytes from 192.168.0.1: icmp_seq=3 ttl=64 time=4.26 ms
64 bytes from 192.168.0.1: icmp_seq=4 ttl=64 time=4.01 ms
64 bytes from 192.168.0.1: icmp_seq=5 ttl=64 time=6.69 ms
64 bytes from 192.168.0.1: icmp_seq=6 ttl=64 time=4.93 ms
64 bytes from 192.168.0.1: icmp_seq=7 ttl=64 time=8.30 ms
64 bytes from 192.168.0.1: icmp_seq=8 ttl=64 time=4.17 ms