Skip to content

Instantly share code, notes, and snippets.

@okeuday
okeuday / gist:5b111960e2904eed244d
Created May 30, 2014 00:43
Why is test1 shorter?
test1(A) ->
if
A =:= true ->
ok;
A =:= false ->
error
end.
test2(A) ->
case A of
true ->
@okeuday
okeuday / abstract_code.erl
Created July 28, 2014 22:03
Getting abstract code in erlang
%%% -*- coding: utf-8; Mode: erlang; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
%%% ex: set softtabstop=4 tabstop=4 shiftwidth=4 expandtab fileencoding=utf-8:
%%%
%%%------------------------------------------------------------------------
%%% @doc
%%% ==Abstract Code Insertion==
%%% A method to get the abstract code representation directly from the
%%% binary beam module representation.
%%%
%%% Other methods could be used, but they are not as efficient.
@okeuday
okeuday / streams.erl
Last active August 29, 2015 14:05
streams module
-module(streams).
-author('tobbe@erix.ericsson.se').
%%
%% Author: Torbjorn Tornkvist
%% http://forum.trapexit.org/viewtopic.php?p=22424#22424
%%
%% Date: 27 Nov 1995
%%
%% Try this:
%%
@okeuday
okeuday / package.exs
Created October 13, 2014 20:28
hex.pm package file
defmodule ErlangSyslog.Mixfile do
use Mix.Project
def project do
[app: :syslog,
version: "1.0.3",
description: description,
package: package,
deps: deps]
end
...
Path = [_ | _] = os:getenv("TEST_DIR"),
ReleaseConfig = filename:join([Path, "..", "rel", "files", "app.config"]),
{ok, _} = reltool_util:config_load(ReleaseConfig),
...
ok = reltool_util:application_start(?APPLICATION,
[{listen_ip, {127,0,0,1}},
{listen_port, ?PORT}], infinity),
...
@okeuday
okeuday / gist:6614126
Last active December 23, 2015 09:19
cowboy patch for barrel usage from Aug 17 11:40, changes from https://github.com/refuge/cowboy
diff --git a/Makefile b/Makefile
index 79c2b6c..28cb135 100644
--- a/Makefile
+++ b/Makefile
@@ -10,9 +10,9 @@ PLT_APPS = crypto public_key ssl
# Dependencies.
-DEPS = ranch
+DEPS = barrel
%%%------------------------------------------------------------------------
%%% @doc
%%% ==Abstract Code Insertion==
%%% A method to get the abstract code representation directly from the
%%% binary beam module representation.
%%%
%%% Other methods could be used, but they are not as efficient.
%%% A more obvious method is to use "-compile(debug_info).", but
%%% this approach does not work in practice (despite the documentation)
%%% and would cause the generated code to be inefficient if it did work.
@okeuday
okeuday / gist:6832394
Created October 4, 2013 20:42
uuid run
TEST uuid_creation
N == 100000 (10 runs)
erlang:make_ref/0 get: 7161.7 us ( 1.0)
v1 erlang get: 79289.2 us ( 11.1)
v1 os get: 72063.8 us ( 10.1)
v3 get: 78722.5 us ( 11.0)
v3 compat get: 73597.6 us ( 10.3)
v4 crypto strong get: 218098.7 us ( 30.5)
v4 crypto weak get: 219091.8 us ( 30.6)
v4 random bigint get: 197156.6 us ( 27.5)
@okeuday
okeuday / decompile.erl
Created January 21, 2014 20:19
decompile.erl
-module(decompile).
-export([file/1]).
file(ModuleName) when is_atom(ModuleName) ->
case code:which(ModuleName) of
BeamFilePath when is_list(BeamFilePath) ->
file(BeamFilePath);
Error when is_atom(Error) ->
Error
end;
@okeuday
okeuday / gist:7e4549cb030077db5fa4
Created February 19, 2016 03:00
integer_key, binary_key, string_key (https://github.com/okeuday/erlbench)
Core i7 2670QM 2.2GHz 1 cpu, 4 cores/cpu, 2 hts/core
L2:4×256KB L3:6MB RAM:8GB:DDR3-1333MHz
Sandy Bridge-HE-4 (Socket G2)
TEST integer_key
N == 10 (10 runs)
aadict get: 2.5 us ( 25.0), set: 9.6 us ( 8.0)
array (dynamic) get: 1.0 us ( 10.0), set: 3.7 us ( 3.1)
array (fixed) get: 1.2 us ( 12.0), set: 2.7 us ( 2.3)
btree7 get: 2.6 us ( 26.0), set: 5.2 us ( 4.3)