Let's take my previous chapter example of calculating pi and see how it performs in sync mode (single threaded):

pi = func (x) {

term = func (k) {4 * (-1 ** k) / (2d * k + 1)};

for i = 0; i < x; i = i + 1 { parts[i] = term(i) };

for result = 0, i = 0; i < x; i = i + 1 { result = result + parts[i] };

return result

};

pi(100000)

executes in about 450 ms

in parallel mode it executes in: 375 ms, we get a bit of a gain, but we pound the processors a bit more.

I have optimized the parallel implementation to:

piPart = func (s, x) {

term = func sync (k) {4 * (-1 ** k) / (2d * k + 1)};

for i = s; i < x; i = i + 1 {

parts[i] = term(i)

};

for result = 0, i = s; i < x; i = i + 1 {

result = result + parts[i]

};

return result

};

pi = func (x, breakup) {

range = x / breakup;

l = breakup - 1;

for i = 0, result = 0, k = 0; i < l; i = i + 1 {

part[i] = piPart(k, k + range);

k = k + range

};

part[i] = piPart(k, x);

for i = 0, result = 0; i < breakup; i = i + 1 {

result = result + part[i]

};

return result

};

pi(100000, 5)

and it executes in about 230 ms, about twice faster than the single threaded implementation.

Tests have been executed on a 4 core laptop and they significantly impaired by power management which modifies frequency, disables cores ...

Performance it still far away from the single threaded java implementation which executes in 10 ms...

Will probably be able to get the times closer if I implement ++ and += in zel, but will probably still be far away from java.