This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule TasteTest do | |
use ExUnit.Case | |
setup context do | |
{:ok, Map.put(context, :test, String.to_atom("#{context[:test]} (#{context[:group]})"))} | |
end | |
test "the truth" do | |
assert 1 + 1 == 2 | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule R do | |
def sample_file_inefficient(path, count) do | |
s = File.stream!(path, [], :line) | |
sample = Enum.take(s, count) |> List.to_tuple | |
Stream.drop(s, count) | |
|> Stream.with_index | |
|> Enum.reduce(sample, fn {line, index}, sample -> | |
case random(index) do | |
r when r < count -> put_elem(sample, r, line) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f = fn x -> {:ok, {x, [1,x,3]}} end | |
import M | |
f.(2) |> match!({:ok, {!x, _}}) | |
#=> 2 | |
f.(2) |> match!({:ok, {x, [1,!x,3]}}) | |
#=> 2 | |
f.(2) |> match!({:ok, {13, [1,!x,3]}}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import M | |
File.read("match.exs") |> match({:ok, bin}, bin) |> String.length | |
#=> 156 | |
s = """ | |
id;name;value | |
1;foo;hi | |
2;bar;bye | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <assert.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <mach/mach_time.h> | |
#include <stdint.h> | |
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Benchfella.start duration: 1.0 | |
defmodule StringDuplicateBench do | |
use Benchfella | |
Enum.each([100, 1000, 10000, 100000], fn n -> | |
@str "1234567890" | |
@n n | |
bench "binary copy #{n}" do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Benchfella.start duration: 1.0, format: :machine, verbose: true | |
defmodule StringSlice do | |
use Benchfella | |
Enum.each([100, 1000, 10000], fn n -> | |
@str String.duplicate("hello world", n) | |
@len String.length(@str) | |
bench "negative both #{n}" do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# master | |
StringSlice.slice left half: 100 20628.67 µs/op | |
StringSlice.slice right half: 50 33514.14 µs/op | |
StringSlice.slice almost all: 50 40865.84 µs/op | |
StringSlice.slice -1: 50 63981.30 µs/op | |
# PR | |
StringSlice.slice -1: 10000000 0.60 µs/op | |
StringSlice.slice left half: 100 15272.15 µs/op | |
StringSlice.slice right half: 50 29207.42 µs/op |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
** (ArgumentError) argument error | |
:erlang.length(Kernel) | |
(elixir) lib/kernel/typespec.ex:494: Kernel.Typespec.type_to_signature/1 | |
(elixir) lib/kernel/typespec.ex:286: anonymous fn/3 in Kernel.Typespec.defines_type?/3 | |
(stdlib) lists.erl:1223: :lists.any/2 | |
(elixir) lib/kernel/typespec.ex:289: Kernel.Typespec.defines_type?/3 | |
lib/porcelain/process.ex:16: (module) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BenchfellaBench.binary test 10: 10000000 0.13 µs/op | |
BenchfellaBench.binary test 100: 10000000 0.13 µs/op | |
BenchfellaBench.binary test: 10000000 0.13 µs/op | |
BenchfellaBench.binary test 1000: 10000000 0.13 µs/op | |
BenchfellaBench.range test: 100000 26.93 µs/op | |
BenchfellaBench.range test 10: 10000 293.43 µs/op | |
BenchfellaBench.range test 100: 500 3312.59 µs/op | |
BenchfellaBench.range test 1000: 50 32802.00 µs/op |