[julia-users] why so much faster with a global than a local vec?
In the local case, it is having to allocate, populate, and then at some point garbage collect that array. That is why using a const is much faster.
Re: [julia-users] why so much faster with a global than a local vec?
The first one creates a new array object every time it runs. It's a fairly sophisticated analysis to prove that the array never escapes and is never modified and can therefore be reused. On Fri, Jul 3, 2015 at 2:21 PM, Jeffrey Sarnoff jeffrey.sarn...@gmail.com wrote: I wrote a range limited isa_leapyear(year) good in 1800..2200. Your look is appreciated; I do not understand this: The first version runs 50x more slowly than the second version. The first is better practice, is there a way to make it behave? They differ only in placing the bit table (local vs const global). I ran both through code_typed(), the function code is the same. this is the way of the snail: function is_proximal_leapyear(year::Int) LeapYearBitTbl = [ 0xfdfe, 0x, 0xf7ff, 0x000f ] y400 = convert(Uint32, year-1800) y100 = y400 2 mask = one(Uint32) (y100 0x000f) indx = 1 + (y100 5) ((LeapYearBitTbl[indx] $ mask) + (y400 0x0003)) === zero(Uint32) end this way is lovely fast: const LeapYearBitTable = [ 0xfdfe, 0x, 0xf7ff, 0x000f ]; function isa_proximal_leapyear(year::Int) y400 = convert(Uint32, year-1800) y100 = y400 2 mask = one(Uint32) (y100 0x000f) indx = 1 + (y100 5) ((LeapYearBitTable[indx] $ mask) + (y400 0x0003)) === zero(Uint32) end
[julia-users] why so much faster with a global than a local vec?
I wrote a range limited isa_leapyear(year) good in 1800..2200. Your look is appreciated; I do not understand this: The first version runs 50x more slowly than the second version. The first is better practice, is there a way to make it behave? They differ only in placing the bit table (local vs const global). I ran both through code_typed(), the function code is the same. this is the way of the snail: function is_proximal_leapyear(year::Int) LeapYearBitTbl = [ 0xfdfe, 0x, 0xf7ff, 0x000f ] y400 = convert(Uint32, year-1800) y100 = y400 2 mask = one(Uint32) (y100 0x000f) indx = 1 + (y100 5) ((LeapYearBitTbl[indx] $ mask) + (y400 0x0003)) === zero(Uint32) end this way is lovely fast: const LeapYearBitTable = [ 0xfdfe, 0x, 0xf7ff, 0x000f ]; function isa_proximal_leapyear(year::Int) y400 = convert(Uint32, year-1800) y100 = y400 2 mask = one(Uint32) (y100 0x000f) indx = 1 + (y100 5) ((LeapYearBitTable[indx] $ mask) + (y400 0x0003)) === zero(Uint32) end
Re: [julia-users] why so much faster with a global than a local vec?
On Fri, Jul 3, 2015 at 8:37 AM, Stefan Karpinski ste...@karpinski.org wrote: The first one creates a new array object every time it runs. It's a fairly sophisticated analysis to prove that the array never escapes and is never modified and can therefore be reused. Also, in general, a global constant is faster than a local variable. On Fri, Jul 3, 2015 at 2:21 PM, Jeffrey Sarnoff jeffrey.sarn...@gmail.com wrote: I wrote a range limited isa_leapyear(year) good in 1800..2200. Your look is appreciated; I do not understand this: The first version runs 50x more slowly than the second version. The first is better practice, is there a way to make it behave? They differ only in placing the bit table (local vs const global). I ran both through code_typed(), the function code is the same. this is the way of the snail: function is_proximal_leapyear(year::Int) LeapYearBitTbl = [ 0xfdfe, 0x, 0xf7ff, 0x000f ] y400 = convert(Uint32, year-1800) y100 = y400 2 mask = one(Uint32) (y100 0x000f) indx = 1 + (y100 5) ((LeapYearBitTbl[indx] $ mask) + (y400 0x0003)) === zero(Uint32) end this way is lovely fast: const LeapYearBitTable = [ 0xfdfe, 0x, 0xf7ff, 0x000f ]; function isa_proximal_leapyear(year::Int) y400 = convert(Uint32, year-1800) y100 = y400 2 mask = one(Uint32) (y100 0x000f) indx = 1 + (y100 5) ((LeapYearBitTable[indx] $ mask) + (y400 0x0003)) === zero(Uint32) end