diff options
author | David Walter Seikel | 2014-04-21 20:59:39 +1000 |
---|---|---|
committer | David Walter Seikel | 2014-04-21 20:59:39 +1000 |
commit | 9621add2918cc4943e6693b74ae85d51dd264fcf (patch) | |
tree | fff1edf2c69d7a08a0e12885eecc9b96ed847a6a /LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/fib.lua | |
parent | LuaSL_test's window doesn't need to be so huge. (diff) | |
download | SledjHamr-9621add2918cc4943e6693b74ae85d51dd264fcf.zip SledjHamr-9621add2918cc4943e6693b74ae85d51dd264fcf.tar.gz SledjHamr-9621add2918cc4943e6693b74ae85d51dd264fcf.tar.bz2 SledjHamr-9621add2918cc4943e6693b74ae85d51dd264fcf.tar.xz |
We don't need the testlua directory any more.
Diffstat (limited to '')
-rw-r--r-- | LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/fib.lua | 40 |
1 files changed, 0 insertions, 40 deletions
diff --git a/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/fib.lua b/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/fib.lua deleted file mode 100644 index 97a921b..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/test_lua/5.1/fib.lua +++ /dev/null | |||
@@ -1,40 +0,0 @@ | |||
1 | -- fibonacci function with cache | ||
2 | |||
3 | -- very inefficient fibonacci function | ||
4 | function fib(n) | ||
5 | N=N+1 | ||
6 | if n<2 then | ||
7 | return n | ||
8 | else | ||
9 | return fib(n-1)+fib(n-2) | ||
10 | end | ||
11 | end | ||
12 | |||
13 | -- a general-purpose value cache | ||
14 | function cache(f) | ||
15 | local c={} | ||
16 | return function (x) | ||
17 | local y=c[x] | ||
18 | if not y then | ||
19 | y=f(x) | ||
20 | c[x]=y | ||
21 | end | ||
22 | return y | ||
23 | end | ||
24 | end | ||
25 | |||
26 | -- run and time it | ||
27 | function test(s,f) | ||
28 | N=0 | ||
29 | local c=os.clock() | ||
30 | local v=f(n) | ||
31 | local t=os.clock()-c | ||
32 | print(s,n,v,t,N) | ||
33 | end | ||
34 | |||
35 | n=arg[1] or 24 -- for other values, do lua fib.lua XX | ||
36 | n=tonumber(n) | ||
37 | print("","n","value","time","evals") | ||
38 | test("plain",fib) | ||
39 | fib=cache(fib) | ||
40 | test("cached",fib) | ||