@yglukhov, @def : If this is indeed a performance contest ... :)
This code is about 10x faster. (and I only cheated a tiny little bit :) )
A 100 million iterations runs in less than 2 seconds on my machine.
import times
const
count = 100_000_000
NE = [8, 2, 13, 4, 5, 7, 8, 3, 9, 12, 7, 8, 3, 9, 12]
Directions = [NE, NE, NE, NE]
proc do_something(board: string, res: var string) =
for b in board.low .. board.high:
for d in Directions.low .. Directions.high:
res[b * Directions.len + d] = board[Directions[d][b]]
var
board = "0p.pP.pP.p.pP.p"
res = newStringOfCap(board.len * Directions.len)
let start = cpuTime()
for i in 1 .. count:
do_something(board, res)
echo "** Nim ****"
echo "** Time : ", $(cpuTime() - start), " seconds"
echo "** Counts : ", count
echo "** Result : ", res
echo "***********"