I don't know much about @simd. I see it pop up when people use loops made up of very simple arithmetic operations, but I don't know if map can take advantage of it for your more complicated function.
On Friday, October 7, 2016 at 4:29:20 AM UTC-4, Martin Florek wrote: > > Thanks Andrew for answer. > I also have experience that eachindex() is slightly faster. In Performance > tips I found macros e.g. @simd. Do you have any experience with them? > > On Thursday, 6 October 2016 16:13:22 UTC+2, Martin Florek wrote: >> >> >> Hi All, >> >> I'm new in Julia and I need to decide about the more correct/better >> implementation for two data collection. I have implemented mean absolute >> percentage error (MAPE) for *Generator Expressions* (Comprehensions >> without brackets): >> >> a = rand(10_000_000) >> p = rand(10_000_000) >> >> err(actual, predicted) = (actual - predicted) / actual >> >> f(a, p) = 100 * sumabs(err(a[i], p[i]) for i in eachindex(a)) /length(a) >> >> a with *mapreduce()* function. >> >> function mapre(a, p) >> s = mapreduce(t -> begin b,c=t; abs((b - c) / b) end, +, zip(a, p)) >> s * 100/length(a) >> end >> >> When compare *@time f(a,p) *I get: >> >> 0.026515 seconds (11 allocations: 304 bytes) 797.1301337918511 >> >> and *@time mapre(a, p):* >> >> 0.079932 seconds (9 allocations: 272 bytes) 797.1301337918511 >> >> >> Thanks in advance, >> Martin >> >