/mobile Handheld Friendly website

 performance measurements

Each table row shows performance measurements for this Lua program with a particular command-line input value N.

 N  CPU secs Elapsed secs Memory KB Code B ≈ CPU Load
500,0000.180.18?264  0% 0% 0% 100%
5,000,0001.741.751,536264  0% 0% 1% 100%
50,000,00017.4417.451,540264  0% 0% 0% 100%

Read the ↓ make, command line, and program output logs to see how this program was run.

Read thread-ring benchmark to see what this program should do.

 notes

Lua 5.2.1 Copyright (C) 1994-2012 Lua.org, PUC-Rio

 thread-ring Lua #3 program source code

-- The Computer Language Benchmarks Game
-- http://benchmarksgame.alioth.debian.org/
-- contributed by Sam Roberts
-- reviewed by Bruno Massa

require"coroutine"

-- first and only argument is number of token passes
local n         = assert(tonumber(arg[1]))

-- fixed size pool
local poolsize  = 503
local threads   = {}

-- cache these to avoid global environment lookups
local create    = coroutine.create
local resume    = coroutine.resume
local yield     = coroutine.yield

local id        = 1
local token     = 0
local ok

local body = function(token)
  while true do
    token = yield(token + 1)
  end
end

-- create all threads
for id = 1, poolsize do
  threads[id] = create(body)
end

-- send the token
repeat
  if id == poolsize then
    id = 1
  else
    id = id + 1
  end
  ok, token = resume(threads[id], token)
until token == n

print(id)

 make, command-line, and program output logs

Tue, 29 Jan 2013 23:59:02 GMT

COMMAND LINE:
/usr/local/src/lua-5.2.1/install/bin/lua  threadring.lua-3.lua 50000000

PROGRAM OUTPUT:
292

Revised BSD license

  Home   Conclusions   License   Play