Hello Carl and welcome to the Julia community (and fan club). Regarding your question: 1. `normal_sum` version is the one of the most optimized construct you can imagine. So it is good it's working so fast, even relative with a less common Task construct. 2. `values` seems to be a global variable (and not const) which is a source of trouble for Julia type-inference based optimization (it is mentioned in the Performance Tips). So try to wrap up things in a function or make them const (but make sure they are not global which cannot be relied to keep their types).
Dan On Saturday, April 2, 2016 at 2:55:51 PM UTC+3, Carl wrote: > > 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 > >
