Re: Noob benchmark :-)

  • From: "voidptr69@xxxxxxxxxxx" <voidptr69@xxxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Thu, 9 Jul 2015 17:31:11 -0400



Noob ducking now ... and looking if a language war is starting :oP

:-) I took part of the lunch break to extract some sample code ( of course the full code is more complex)...
but you got here the basic idea how to implement your solver, transition m is in this test top face clock turn.

Part of this test is to see how well it handle array ...

And o my machine I stiil got pretty much the same ranking
python3 35sec, lua 20secs, luajit 0.2sec
:o)

Lua
-------------------------------------------

ca = { 'w','w','w','w','w','w','w','w','w', 'b','b','b','b','b','b','b','b','b', 'o','o','o','o','o','o','o','o','o', 'g','g','g','g','g','g','g','g','g', 'r','r','r','r','r','r','r','r','r', 'y','y','y','y','y','y','y','y','y' }

cb = { 'x','x','x','x','x','x','x','x','x', 'x','x','x','x','x','x','x','x','x', 'x','x','x','x','x','x','x','x','x', 'x','x','x','x','x','x','x','x','x', 'x','x','x','x','x','x','x','x','x', 'x','x','x','x','x','x','x','x','x' }

cc = { 'w','w','w','w','w','w','w','w','w', 'o','o','o','b','b','b','b','b','b', 'g','g','g','o','o','o','o','o','o', 'r','r','r','g','g','g','g','g','g', 'b','b','b','r','r','r','r','r','r', 'y','y','y','y','y','y','y','y','y' }

m = { 7,4,1,8,0,2,9,6,3, 19,20,21,0,0,0,0,0,0, 28,29,30,0,0,0,0,0,0, 37,38,39,0,0,0,0,0,0, 10,11,12,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0 }


function cubeMove(ca, cb)

for x = 1, 54 do
if m[x] == 0 then
cb[x] = ca[x]
else
cb[x] = ca[m[x]]
end
end
end

function cubeEqual(ca, cb)

for x = 1, 54 do
if ca[x] ~= cb[x] then
return false
end
end
return true
end


cubeMove(ca, cb)
assert(cubeEqual(cb, cc))


for x = 1, 2000000 do
cubeMove(ca, cb)
if not cubeEqual(cb, cc) then
assert(false)
end
end

-----


Python 3
--------------------------------------------------------


#!python3

ca = ['_', 'w','w','w','w','w','w','w','w','w', 'b','b','b','b','b','b','b','b','b', 'o','o','o','o','o','o','o','o','o', 'g','g','g','g','g','g','g','g','g', 'r','r','r','r','r','r','r','r','r', 'y','y','y','y','y','y','y','y','y' ]
cb = ['_', 'x','x','x','x','x','x','x','x','x', 'x','x','x','x','x','x','x','x','x', 'x','x','x','x','x','x','x','x','x', 'x','x','x','x','x','x','x','x','x', 'x','x','x','x','x','x','x','x','x', 'x','x','x','x','x','x','x','x','x' ]
cc = ['_', 'w','w','w','w','w','w','w','w','w', 'o','o','o','b','b','b','b','b','b', 'g','g','g','o','o','o','o','o','o', 'r','r','r','g','g','g','g','g','g', 'b','b','b','r','r','r','r','r','r', 'y','y','y','y','y','y','y','y','y' ]
m = [ 0, 7,4,1,8,0,2,9,6,3, 19,20,21,0,0,0,0,0,0, 28,29,30,0,0,0,0,0,0, 37,38,39,0,0,0,0,0,0, 10,11,12,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0 ]

def cubeMove(ca, cb):
for x in range(1,55):
if m[x] == 0:
cb[x] = ca[x]
else:
cb[x] = ca[m[x]]

def cubeEqual(ca, cb):
for x in range(1, 55):
if ca[x] != cb[x]:
return False
return True

cubeMove(ca, cb)
assert(cubeEqual(cb, cc))

for x in range(1, 2000000):
cubeMove(ca, cb)
if not cubeEqual(cb, cc):
assert(False)


------------------------

Other related posts: