Thanks, using Float32 speeds up the code a bit:
*julia> **function f1()*
* a=2.0*
* for i=1:1000000*
* a+=exp(a%2+1);*
* end*
* @printf "%20.5e \n" a*
*end*
*f1 (generic function with 1 method)*
*julia> **@time f1()*
8.75047e+06
elapsed time: 0.068128135 seconds (805832 bytes allocated)
*julia> **@time f1()*
8.75047e+06
elapsed time: 0.045130403 seconds (528 bytes allocated)
*julia> **@time f1()*
8.75047e+06
elapsed time: 0.045146918 seconds (528 bytes allocated)
*julia> **function f2()*
* a::Float32 = 2.0*
* b::Float32 = 2.0*
* for i=1:1000000*
* a += exp(a%b + 1)*
* end*
* @printf "%20.5e \n" a*
*end*
*f2 (generic function with 1 method)*
*julia> **@time f2()*
8.74511e+06
elapsed time: 0.051448558 seconds (728816 bytes allocated)
*julia> **@time f2()*
8.74511e+06
elapsed time: 0.035552156 seconds (528 bytes allocated)
*julia> **@time f2()*
8.74511e+06
elapsed time: 0.035797496 seconds (528 bytes allocated)
I think a=2.0f32 gives something different from what I intended:
*julia> **a = 2.0f32*
*2.0f32*
*julia> **@printf "%10.5e \n" a*
2.00000e+32
On Wednesday, February 18, 2015 at 8:40:48 PM UTC-6, Kuba Roth wrote:
>
> I think this comparison is not fair since C++ version uses float32 and
> Julia float64 by default.
> If you provide that information to the compiler the results are similar.
>
> function test1()
> a=2.0f32
> for i=1:1000000
> a+=exp(a%2.0f32);
> end
> end
>
> @time test1()
>
> Julia elapsed time: 0.018281912 seconds (125220 bytes allocated)
> C++ me 30000 clicks (0.030000 seconds).
>
>
> Interstingly Julia's example using Integer in mod operation is slower:
> a+=exp(a%2);
> elapsed time: 0.049916461 seconds (304116 bytes allocated)
>
> These toy benchmarks are pointless anyway.