I was bored with normal stuff and had an hour to burn, so I decided to write the start of a new language.
It's syntax is lua'ish right now. Strongly typed (after all, I have yet to see a lua script that treated the language like a weakly typed language and not like a strongly typed language, checked your lua files too, still treats it like strongly typed, and strongly typed let's me do speed enhancements). Uses integer math right now (easily changeable, plus the scaffolding for a full type system). Basically wrote enough for it to do the Fibonacci function. I then wrote the identical function in lua (same syntax for something that simple) and python:
LUA and my play language:
function fib(num)
if num < 2 then
return num
end
return fib(num-1)+fib(num-2)
end
print(fib(%i))
Although for lua it is actually run as (to minimize time from opening file, just put directly on the command-line):
G:\SDKs\lua\lua-5.1.3\src>lua -e "function fib(num) if num == 1 then return 1 end if num == 0 then return 0 end return fib(num-1)+fib(num-2) end print(fib(%i))"
14930352
Python is (not embedded in the command line as I was too lazy to do so):
def fib(n):
if n < 2:
return n
return fib(n-1)+fib(n-2)
Using my 'super accurate' timer (a program that gets the millisecond time before run, runs the command, and returns the current millisecond time minus the old millisecond time) this is what I got:
G:\SDKs\lua\lua-5.1.3\src>timeall 30
Running Lua:
832040
Time taken for lua: 0.578000
Could not get LuaJIT to compile, if you have a precompiled version for windows,
please sendRunning ODL1Code (no optimizations, debug info is on)
Will full interprete
checking: ok
running fib(30)
Result: 832040
Time taken for non-optimized ODL1Code: 7.672000
Running ODL1Code (with optimizations, debug info is on)
Will optimize
checking: ok
running fib(30)
Result: 832040
Time taken for optimized ODL1Code: 0.062000
Running Python (no psyco)
832040
Time taken for Python (no psyco): 1.125000
Running Python (with psyco)
832040
Time taken for Python (with psyco): 0.031000
Lua is quite fast on math, surprised.
Python of course sucks on anything based on numbers.
Python JIT'ed (with psyco) compiles to machine code, should be about C speed, so unsurprisingly fast.
Mine, unoptimized (interpreted through the AST in other words), freakishly slow.
Mine, optimized (everything is as low-level as possible), much faster then python and lua, about double the speed of pysco.
I could not get the LuaJIT to compile, ton of include errors when running the vc compile bat file they say to run, but it would probably be about psyco speed too, maybe a bit slower due to it not being strongly typed.
Ran it again at 35 (tried 40, but waited over a minute for lua's to complete, that took too long), mine still took too long with the unoptimized version so commented out its test (I canceled it after a minute as well):
G:\SDKs\lua\lua-5.1.3\src>timeall 35
Running Lua:
9227465
Time taken for lua: 6.000000
Could not get LuaJIT to compile, if you have a precompiled version for windows,
please send
Running ODL1Code (with optimizations, debug info is on)
checking: ok
running fib(35)
Result: 9227465
Time taken for optimized ODL1Code: 0.156000
Running Python (no psyco)
9227465
Time taken for Python (no psyco): 12.203000
Running Python (with psyco)
9227465
Time taken for Python (with psyco): 0.390000
Mine is actually faster then psyco's, fun...
Tested again at 40, commenting out python, lua, and my unoptimized version:
G:\SDKs\lua\lua-5.1.3\src>timeall 40
Running ODL1Code (with optimizations, debug info is on)
Will optimize
verifying... OK
---------
starting fibonacci(40)...
Result: 102334155
Time taken for optimized ODL1Code: 1.125000
Running Python (with psyco)
102334155
Time taken for Python (with psyco): 4.453000
And for the heck of it, 45:
G:\SDKs\lua\lua-5.1.3\src>timeall 45
Running ODL1Code (with optimizations, debug info is on)
Will optimize
verifying... OK
---------
starting fibonacci(45)...
Result: 1134903170
Time taken for optimized ODL1Code: 11.875000
Running Python (with psyco)
1134903170
Time taken for Python (with psyco): 48.953000
Decided to make a c program of the following code:
int fib(int n)
{
if(n < 2) return n;
return fib(n-1)+fib(n-2);
}
int main(int argc, char* argv[])
{
int n = argc > 1 ? atol(argv[1]) : 24;
printf("%i", fib(n));
return 0;
}
With the relevant includes of course.
Ran it through the timer with the given values:
G:\SDKs\lua\lua-5.1.3\src>timeall 30
Running C code 30
832040 Time taken for C code at 30: 0.062000
Running C code 35
9227465 Time taken for C code at 35: 0.188000
Running C code 40
102334155 Time taken for C code at 40: 1.672000
Running C code 45
1134903170 Time taken for C code at 45: 18.890000
And this was with high speed optimizations
Something seems amiss here, I think I need to check a few things, that or my script's engine is 'optimizing' better then the VC2k5 compiler. All the values and such are correct though... so... the heck?
EDIT1: I think it is this optimizing library I am using, it seems... efficient... more so then the visual compiler... If so then this could make writing little languages... fun... Kinda wish I had a fortran compiler to test since it is supposed to be the best one for any math work...
EDIT2: Hmm, wonder how easy a language with coroutinish things would be, this could be my replacement for C++, I have a C++ lexer here, make a few modifications, hmm...
EDIT3: Recompiled the program in VS2k3 instead of VS2k5, got pretty much identical times, so it is not just vs2k5 at issue...