Strange performance behaviour

  • From: Henk Boom <henk@xxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Sat, 25 Aug 2012 17:01:18 -0400

I'm getting some strange performance behaviour with this example. It's
very synthetic but I have another program that can access a buffer in
a similar pattern under some circumstances.

I'm not sure if this is something to do with luajit or just something
about memory access pattern efficiency that I don't know about, but
either way knowing what's making it happen would help me to find out
what to avoid :)

---- test.lua
local ffi = require 'ffi'
local buffer = ffi.new('double[2]')

local n = tonumber((...))
for i = 0, 4e8 do
  buffer[0] = buffer[0] + buffer[n] * 0.1
  buffer[0] = buffer[0] + buffer[n] * 0.1
  buffer[0] = buffer[0] + buffer[n] * 0.1
  buffer[0] = buffer[0] + buffer[n] * 0.1
  buffer[0] = buffer[0] + buffer[n] * 0.1
  buffer[0] = buffer[0] + buffer[n] * 0.1
  buffer[0] = buffer[0] + buffer[n] * 0.1
  buffer[0] = buffer[0] + buffer[n] * 0.1
end
----

henk@mehve:~/Desktop$ time ./luajit test.lua 0

real    0m14.669s
user    0m14.645s
sys     0m0.004s
henk@mehve:~/Desktop$ time ./luajit test.lua 1

real    0m3.158s
user    0m3.152s
sys     0m0.000s

Other related posts: