Created
March 25, 2016 11:56
-
-
Save fenollp/b454795747cfb8b5d754 to your computer and use it in GitHub Desktop.
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
%% Copyright © 2016 Pierre Fenoll ‹pierrefenoll@gmail.com› | |
%% See LICENSE for licensing information. | |
%% -*- coding: utf-8 -*- | |
-module(cmp_fun_v_func). | |
%% cmp_fun_v_func: compare calling a function vs calling a function applying a fun. | |
%% 44> G = fun (Fun, Times) -> lists:sum([T || _ <- lists:seq(1,Times), {T,_Ret} <- [timer:tc(cmp_fun_v_func, Fun, [Times])]]) / Times end. | |
%% #Fun<erl_eval.12.50752066> | |
%% 45> G(fn, 1000000). G(fnc, 1000000). | |
%% 1.044192 | |
%% 46> G(fnc, 1000000). | |
%% 1.081405 | |
-export([ fn/1 | |
, fnc/1 | |
]). | |
%% API | |
fn(A) -> | |
3 * A. | |
fnc(A) -> | |
F = fun fn/1, | |
fnc(F, A). | |
%% Internals | |
fnc(F, A) -> | |
F(A). | |
%% End of Module. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment