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: 3 2012-01-25 0:07

>>1
hundreds of thousands of times (sic)
<= 50ms

V8 wins.

$ cat > time.lisp
(defun analyze (s)
  (time
    (loop for i from 1 to 100000 do
          (eval s))))
(loop (analyze (read)))
$ sbcl --script time.lisp
Evaluation took:
  0.241 seconds of real time
  0.239984 seconds of total run time (0.236651 user, 0.003333 system)
  99.59% CPU
  300,000 forms interpreted
  674,617,678 processor cycles
  14,415,488 bytes consed

$ cat > time.lua
function analyze(s)
    local start = os.clock()
    for i = 1, 100000 do
        assert(loadstring(s))()
    end
    print(os.clock() - start, "s")
end
for expr in io.lines() do
    analyze(expr)
end
$ luajit2 time.lua
math.sqrt(math.random(1000))
0.17 s

$ cat > time.js
function analyze(s) {
    var start = (new Date).getTime();
    for (var i = 0; i < 100000; i++) {
        eval(s);
    }
    print((new Date).getTime() - start, "ms");
}
while (expr = readline()) {
    analyze(expr);
}
$ d8 time.js
Math.sqrt(Math.random(1000))
36 ms

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