Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

javascript vs lua

Name: Anonymous 2012-01-24 20:47

let's say i might be working on something ``secret'' and i want to embed a scripting language that isn't too off the wall for end users. i hear luajit is kinda fast and v8 is really fast and speed would be quite nice since user scripts might be called hundreds of thousands of times in short timeframes

i've heard javascript has better semantics and is generally more pleasant to use, but i want /prog/'s opinion so i don't fuck up and regret it later

Name: Anonymous 2012-02-15 13:09

>>119
weak maps that can't be iterated, which is really convenient considering i iterate them in the vast majority of cases i use them:

local objects = setmetatable({ }, { __mode = "k" })
local function Object (x, y)
    local o = { x = tonumber(x) or 0, y = tonumber(y) or 0 }
    objects[o] = true
    return o
end

while true do
    for o in pairs(objects) do
        some_update_function(o)
    end
end

Name: Anonymous 2012-02-15 13:11

>>120
mozilla really really wants people to use poor old javascript, thank you very much! the internet is a nacl-free zone!

Name: Anonymous 2012-02-15 13:50

>>122
nacl is great for exploiting hidden hardware exploits through injection of arbitrary code

Name: Anonymous 2012-02-15 22:58

>>113
>- they aren't enumerable, because the gc collecting fields would fuck up the iteration

what a bunch of retards.

Name: Anonymous 2012-02-15 23:57

>>124
The next thing you know, JavaScript programmers will be declaring types and calling free() because idiots are trying to abuse the poor language for purposes it was never intended for. JavaScript was a simple language designed for small client-side scripts that run inside a webpage, not distributed computing, binary file manipulation, huge games, or enterprise frameworks. "Web app developers" need to find a new language for client-side scripting before they turn JavaScript into the "Objective-C++/CLI" of the web.

Name: Anonymous 2012-02-16 0:01

>>125
but it's already the ``x86 of the web*''!!!

* http://lambda-the-ultimate.org/node/3851#comment-57671

calling something the x86 of anything sure is a compliment!

Name: Anonymous 2012-02-16 0:03

>>126
"I was convinced that we needed to build-in a programming language, but the developers, Tim first, were very much opposed. It had to remain completely declarative. Maybe, but the net result is that the programming-vacuum filled itself with the most horrible kluge in the history of computing: Javascript." - Robert Cailliau
the most horrible kluge in the history of computing
x86 of the web
Sounds about right.

Name: Anonymous 2012-02-16 3:23

>>127
x86 supremacy.

your goy shit will never make it.

Name: Anonymous 2012-02-16 3:29

>>125
I just don't understand why weak maps would be supported, but not iteration on them. Just sayin, that's kind of retarded.

Name: Anonymous 2012-02-16 14:36

>>128
Go suck an infant's cock you mental mohel.

Name: Anonymous 2012-02-17 6:02

>>130
Damn pedo.

Name: Anonymous 2012-02-17 12:09

Name: Anonymous 2012-02-17 12:19

>>130
Penis envy will get you nowhere.

Name: Anonymous 2012-02-17 12:23

>>131
Don't give unmeaningful excuses .

Name: Anonymous 2012-02-17 12:24

>>134
>>132 is unmeaningful.

Name: Anonymous 2012-02-17 19:06

but javascript has v8

Name: Anonymous 2012-02-17 20:16

>>136
but libluajit.so is just ~400k when libv8.so is near 3MB
and is quite competitive, even faster on some benchmarks, for example, n-body:

$ time luajit2 a.lua 5000000
-0.169075164
-0.169083134

real    0m2.926s
user    0m2.896s
sys    0m0.003s
$ time d8 --nodebugger a.js -- 5000000
-0.169075164
-0.169083134

real    0m5.834s
user    0m5.893s
sys    0m0.050s


Code from here http://shootout.alioth.debian.org/u32/program.php?test=nbody&lang=v8&id=1
 and here http://shootout.alioth.debian.org/u32/program.php?test=nbody&lang=lua&id=4

Name: Anonymous 2012-02-17 20:18

my mistake, luajit2 is near 700k, and v8 near 3M

Name: Anonymous 2012-02-17 21:18

>>138
it's 300k for me; you're probably thinking of the source archive

Name: Anonymous 2012-02-18 13:56

http://news.ycombinator.com/item?id=3607207
see that? javascript! don't see them considering lua anywhere!

seriously, quit wasting time and just use v8

Name: Anonymous 2012-02-18 16:11

>>140

why?

Name: Anonymous 2012-02-18 17:00

I'd use lua just because its not jabbashits. The DOM tainted that language forever.

Name: Anonymous 2012-02-18 17:52

Just tried lua.js. Works pretty nice, some built-in functions missing, notably table.concat. No showstoppers, though. All IO is also missing, except print, which outputs to console. I guess someone should write XHR, websockets and local storage library for it. Canvas, events and maybe some DOM-support would be nice too...

https://github.com/mherkender/lua.js

Name: Anonymous 2012-02-18 18:15

Seems like you can run Lua on following platforms, ie. pretty much anywhere.

Nearly all desktop operating systems; All Linux, 32/64-bit Windows, OS X, *BSD, Solaris, Haiku, etc.

Nearly all smartphone platforms: Symbian (incl. Java ME), Android, iOS, Windows Phone 7 (LuaCLR, Kopi Lua, etc.), BlackBerry

Web platforms; Web browsers capable for running Javascript, Adobe Flash, Wikipedia templates

Bytecode based VMs; .net, JVM, LLVM.

Embedded platforms; Many PS3 and Xbox 360 games use Lua, most Canon cameras via CHDK and Magic Lantern, MP3 players supported by Rockbox, large memory (128kB+ RAM) microcontrollers (eLua), many wireless routers (dd-wrt, Tomato, etc.), and a lot more.

Some more implementations here: http://lua-users.org/wiki/LuaImplementations

Name: Anonymous 2012-02-18 18:42

>>143
__mode and __gc metamethods are not supported
lol javascript

harmony mode: only the 'k' option of __mode is supported and iterating the table is a bad idea please dont do it

Name: Anonymous 2012-02-18 18:45

JavaScript is an abomination. The only good thing about it is that it's "higher-level than C." Wow! Of course a scripting language for the web is higher-level than a compiled systems language!

Name: Anonymous 2012-02-18 19:27

>>140

Ported their fib benchmark (javascript version) to Lua.

Windows 7 x64, 2.66 GHz i5, 4GB RAM. Compiled luajit 2.0.0-beta9 using "Microsoft (R) C/C++ Optimizing Compiler Version 16.00.30319.01 for x64".

luajit.exe fib_julia.lua
Lua,fib,0.113

This compares favorably to their benchmarks: http://julialang.org/
https://github.com/JuliaLang/julia/tree/48d39c542f1b2f6049d1d21585e92e3c90705397/test/perf

--

function fib(n)
    if n < 2 then return n end
    return fib(n-1) + fib(n-2)
end

tmin = math.huge
for i=1, 5, 1 do
    t = os.clock()
    for j=1, 1000, 1 do
        assert(fib(20) == 6765)
    end
    t = os.clock()-t
    if t < tmin then tmin = t end
end

print("Lua,fib," .. tmin)

Name: Anonymous 2012-02-18 19:44

So fibs is officially the benchmark of 2012?

Name: Anonymous 2012-02-18 23:56

No, but when trying to convert js perf tests to lua, I've spotted more than two variable scoping bugs..

>>147
And for fibs on my machine..
luajit2 has got ~0.00022s
v8 has got ~0.241ms

>>140 I won't consider v8 anymore, thank you.

Name: Anonymous 2012-02-19 1:15

>>140

This code runs 20% faster. Making function fib local helps a lot.

local function fib(n)
    if n < 2 then return n end
    return fib(n-1) + fib(n-2)
end

local tmin = math.huge

for i=1, 5, 1 do
    local t = os.clock()
    for j=1, 1000, 1 do
        assert(fib(20) == 6765)
    end
    t = os.clock()-t
    if t < tmin then tmin = t end
end

print("Lua,fib," .. tmin)

Name: Anonymous 2012-02-19 1:16

Ooops, meant >>147, not >>140.

Name: Anonymous 2012-02-19 4:07

APL, 18 characters:
↑¨+.×\⎕⍴⊂1 0∘.∨1 0

Name: Anonymous 2012-02-19 5:16

>>150
I see what you've done there... :3

Name: Anonymous 2012-02-19 6:09

I did the julialang.org perftest with luajit2.
$ luajit2 test.lua
luajit2,fib,0.21
luajit2,parse_int,0.53
luajit2,mandel,4.8
luajit2,quicksort,2.3
luajit2,pi_sum,34
luajit2,rand_mat_stat,110
luajit2,rand_mat_mul,16.84
$ node test.js
javascript,fib,0.242
javascript,parse_int,0.497
javascript,mandel,1.376
javascript,quicksort,3.08
javascript,pi_sum,32.2
javascript,rand_mat_stat,66
javascript,rand_mat_mul,62354


But I don't think this is valid, I've found things like 1 < x < 10, unused variables, arithmetic on undefined and NaN values...

Anyway, Luajit is quite on par with V8, but totally outperforms V8's rand_mat_mul time. With this, I can conclude that V8 is amazing, but it was really designed for the web, not as a scientific scripting language, and -- Lua, I choose you!

Name: Anonymous 2012-02-19 8:02

>>154
Nice work there. That's good to know.

Name: Anonymous 2012-11-16 1:13

>>39
I was reading this thread just now, and farted loudly in the middle of reading >>38.
Then, I scrolled down, saw your post, and was so amused by the coincidence that I had to tell you about it.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List