Skip to content

Instantly share code, notes, and snippets.

@amcjen
Created July 11, 2011 16:13
Show Gist options
  • Save amcjen/1076195 to your computer and use it in GitHub Desktop.
Save amcjen/1076195 to your computer and use it in GitHub Desktop.
Erlang process spawning profile
-module(tester).
-export([loopTheFucker/2]).
loopTheFucker(N, Total) when N =/= 0 ->
spawn(fun() -> true end),
loopTheFucker(N-1, Total+N);
loopTheFucker(0, Total) -> Total.
%% After downloading this, run the following in the Erlang shell (erl on the command line):
%% 1> c(tester).
%% 2> fprof:trace(start).
%% 3> tester:loopTheFucker(100000,0).
%% 4> fprof:trace(stop).
%% 5> fprof:profile().
%% 6> fprof:analyse({dest, "profile.txt"}).
%%
%% And then take a look at the profiles.txt file. under "totals", the AAC is the total accumulated time
%% for the entire code to run, including all spawned processes completing. The OWN is the length
%% of time spent only in our loopTheFucker() function. Zoom!
@bdotdub
Copy link

bdotdub commented Jul 23, 2011

14652.397 <- seems high!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment