What wrong with this bench?

bench code
compile with $ valac --disable-assert -X -Ofast -o valabf bf.vala

I rewrote the C# benchmark, from here(brainfuck). But the results are disappointing, vala with Ofast will come out 9 seconds, while C# 4, C++ 2.
(I remade Gee.ArrayList in a regular array that gave 3 seconds( was 12), and the Compact classes that gave a second)
Does such an overhead give the use of GLib, or I do not notice something?

PS If I am changing the Tape in to struct I get double free or corruption (fasttop)
[1] 15104 abort (core dumped)./ valabf bench.b

The foreach loop in _run() copies the entire array every time. Try foreach(unowned Op op…). That shaved off 3/4 of the runtime here.

Omg ty, I knew it, but I didn’t think about it at all. Perhaps because in C# there was the same code, so I didn’t think about how to change the code itself, but only about what structures to change, like List to obynchny [].

Unfortunately in Vala does not work unowned inside foreach: Invalid assignment from owned expression to unowned variable. So I just changed it to for, now its 2.3 seconds!

Interesting. Seemed to work here with Vala 0.40.17

Its really strange, Im on Vala 0.46.5 now.

PS Forgot to–disable-assert flag, now it’s 1.81 s, which is faster then D(2.692), C++(2.04).

Created PR.

@jensgeorg It seems that Vala will take the first place in parsing the big brainfuck program mandel.b https://github.com/nuald/benchmarks/tree/vala-follow-up
UPD in master now https://github.com/kostya/benchmarks

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.