Memory usage can be an issue if you're simply iterating over a long range, 
e.g.

julia> function pi_half_montecarlo(n)
         mysum = 0
         for x in linrange(0,1,n)
           y = rand()
           if x*x + y*y < 1
             mysum += 1
           end
         end
         return 4.0*mysum/n
       end
pi_half_montecarlo (generic function with 1 method)


julia> pi_half_montecarlo(10); @time pi_half_montecarlo(1000_000_000)/pi
elapsed time: 17.980499945 seconds (112 bytes allocated)
1.0000009913475585



This would use 8 GB of RAM if one were to write linspace in Julia 0.3 (or 
collect(linspace(...)) in Julia 0.4). Iterating over FloatRanges/LinSpaces 
may be less common than iterating over UnitRanges, but it's still not that 
far fetched.

The iterator vs array issue was considered important enough to break 
compatibility for "range" between Python 2 and Python 3.


On Thursday, October 22, 2015 at 5:15:17 PM UTC+2, Christoph Ortner wrote:
>
>
>
> On Thursday, 22 October 2015 10:24:50 UTC+1, Andras Niedermayer wrote:
>>
>> You're making a good point about an Array being sometimes faster than a 
>> LinSpace. But a LinSpace gets you a factor N improvement in terms of memory 
>> efficiency for a size N range, an Array only gets you a constant factor 
>> improvement in speed (the factor 15 being admittedly relatively large in 
>> this example).
>>
>> Memory efficiency typically matters more for usability in an exploratory 
>> interactive session: if my Julia session needs 5 GB RAM, a factor 3 
>> increase of memory will crash my computer. If my code runs for 10 seconds 
>> in an interactive session, 30 seconds is mildly annoying, but not a deal 
>> breaker. (Obviously, you can construct different examples with memory/time 
>> where this is different. But my point is that inconvenience changes 
>> discontinuously in memory usage.)
>>
>
> In my domain (PDEs and related), memory usage is hardly ever an issue for 
> one-dimensional arrays (as in I cannot for the life of me think of a case 
> where it is). I don't know about other domains of course.
>
> Christoph
>

Reply via email to