Skip to content

Instantly share code, notes, and snippets.

@maierru
Last active August 27, 2017 11:34
Show Gist options
  • Save maierru/1924545dfa77059262405e0f169a59e3 to your computer and use it in GitHub Desktop.
Save maierru/1924545dfa77059262405e0f169a59e3 to your computer and use it in GitHub Desktop.
ETS select is slow => O(n)
https://github.com/sat2707/hlcupdocs/blob/master/TECHNICAL_TASK.md
iex(9)> :ets.info(:visits)
[read_concurrency: true, write_concurrency: false, compressed: false,
memory: 110008228, owner: #PID<0.3544.0>, heir: :none, name: :visits,
size: 10000740, node: :nonode@nohost, named_table: true, type: :ordered_set,
keypos: 1, protection: :public]
iex(11)> fun = :ets.fun2ms(fn {id, user, location, visited_at, mark} when user == 475422 -> id end)
[{{:"$1", :"$2", :"$3", :"$4", :"$5"}, [{:==, :"$2", 475422}], [:"$1"]}]
iex(13)> :timer.tc(:ets,:select, [:visits, fun])
{995227,
[4900032, 4968401, 5719429, 6199945, 6664262, 6840698, 6978489, 7701343,
9396431, 9659045]}
995 ms!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment