Hello,
Julia is great. I'm new fan and trying to figure out how to write simple
coroutines that are fast. So far I have this:
function task_iter(vec)
@task begin
i = 1
for v in vec
produce(v)
end
end
end
function task_sum(vec)
s = 0.0
for val in task_iter(vec)
s += val
end
return s
end
function normal_sum(vec)
s = 0.0
for val in vec
s += val
end
return s
end
values = rand(10^6)
task_sum(values)
normal_sum(values)
@time task_sum(values)
@time normal_sum(values)
1.067081 seconds (2.00 M allocations: 30.535 MB, 1.95% gc time)
0.006656 seconds (5 allocations: 176 bytes)
I was hoping to be able to get the speeds to match (as close as possible).
I've read the performance tips and I can't find anything I'm doing wrong.
I also tried out 0.5 thinking that maybe it would be faster with
supporting fast anonymous functions but it was slower (1.5 seconds).
Carl