From 3f61d823aef2f977843d2d3e34e3c6d59a811f1e Mon Sep 17 00:00:00 2001 From: rxi Date: Thu, 1 May 2014 19:23:44 +0100 Subject: [PATCH] Changed position of lume.time() function --- README.md | 14 +++++++------- lume.lua | 14 +++++++------- test/test_lume.lua | 14 +++++++------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 4c84bc0..26a8af4 100644 --- a/README.md +++ b/README.md @@ -216,13 +216,6 @@ slow-running computations. fib = lume.memoize(function(n) return n < 2 and n or fib(n-1) + fib(n-2) end) ``` -### lume.time(fn, ...) -Inserts the arguments into function `fn` and calls it. Returns the time in -seconds the function `fn` took to execute followed by `fn`'s returned values. -```lua -lume.time(function(x) return x end, "hello") -- Returns 0, "hello" -``` - ### lume.combine(...) Creates a wrapper function which calls each supplied argument in the order they were passed to `lume.combine()`; nil arguments are ignored. The wrapper @@ -234,6 +227,13 @@ local f = lume.combine(function(a, b) print(a + b) end, f(3, 4) -- Prints "7" then "12" on a new line ``` +### lume.time(fn, ...) +Inserts the arguments into function `fn` and calls it. Returns the time in +seconds the function `fn` took to execute followed by `fn`'s returned values. +```lua +lume.time(function(x) return x end, "hello") -- Returns 0, "hello" +``` + ### lume.lambda(str) Takes a string lambda and returns a function. `str` should be a list of comma-separated parameters, followed by `->`, followed by the expression which diff --git a/lume.lua b/lume.lua index d19c526..a2036c3 100644 --- a/lume.lua +++ b/lume.lua @@ -287,13 +287,6 @@ function lume.memoize(fn) end -function lume.time(fn, ...) - local start = os.clock() - local rtn = {fn(...)} - return (os.clock() - start), unpack(rtn) -end - - function lume.combine(...) local funcs = {} for i = 1, select("#", ...) do @@ -309,6 +302,13 @@ function lume.combine(...) end +function lume.time(fn, ...) + local start = os.clock() + local rtn = {fn(...)} + return (os.clock() - start), unpack(rtn) +end + + local lambda_cache = {} function lume.lambda(str) diff --git a/test/test_lume.lua b/test/test_lume.lua index dabc0fa..603c5d5 100644 --- a/test/test_lume.lua +++ b/test/test_lume.lua @@ -293,13 +293,6 @@ tests["lume.memoize"] = function() testeq( f2(), nil ) end --- lume.time -tests["lume.time"] = function() - local t, a, b, c = lume.time(function(x) return 50, 60, x end, 70) - testeq( type(t), "number" ) - testeq( {a, b, c}, {50, 60, 70} ) -end - -- lume.combine tests["lume.combine"] = function() local acc = 0 @@ -314,6 +307,13 @@ tests["lume.combine"] = function() testeq( acc, 230 ) end +-- lume.time +tests["lume.time"] = function() + local t, a, b, c = lume.time(function(x) return 50, 60, x end, 70) + testeq( type(t), "number" ) + testeq( {a, b, c}, {50, 60, 70} ) +end + -- lume.lambda tests["lume.lambda"] = function() testeq( lume.lambda "x->x*x"(10), 100 )