How much faster is zeros with your PR? IIRC, we used to have something like this in the early days.
https://github.com/JuliaLang/julia/pull/9142/ -viral On Tuesday, November 25, 2014 8:30:00 AM UTC+5:30, Erik Schnetter wrote: > > On Mon, Nov 24, 2014 at 7:19 PM, Stefan Karpinski <[email protected]> > wrote: > > Should the comparison actually be more like this: > > > > julia> @time begin > > x = Array(Int,N) > > fill!(x,1) > > end; > > elapsed time: 6.782572096 seconds (8000000128 bytes allocated) > > > > julia> @time begin > > x = zeros(Int,N) > > fill!(x,1) > > end; > > elapsed time: 14.166256835 seconds (8000000176 bytes allocated) > > > > > > At least that's the comparison that makes sense for code that allocates > and > > then initializes an array. I consistently see a 2x slowdown or more. > > My laptop can zero memory at 6+ GByte/sec. The overhead in your case > should be about ten times less than what you report. I suspect that > what you are measuring is not just the overhead of `zeros` over > `Array`, but something else as well. > > Or Julia's `zeros` is not implemented efficiently. Zeroing memory is > surprisingly CPU intensive, and one has to call `memset`, or has to > ensure that the vectorizer kicks in, and may have to manually unroll > the loops. I'm not sure LLVM gets this right by default... > > ... yes, Julia's `zeros` is not as good as it should be. It calls > `fill!`, but the generated machine code leaves to be desired. Time to > add a special case to `fill!`, delegating things to `memset` in > certain cases? > > -erik > > -- > Erik Schnetter <[email protected]> > http://www.perimeterinstitute.ca/personal/eschnetter/ >
