Memory allocation was 93896 bytes when I ran the function in iJulia
Notebook. When I run it from the console it allocates only 96 bytes as you
suggested!
Thanks very much to all the helpful messages!
On Wednesday, February 18, 2015 at 8:10:35 PM UTC-6, Stefan Karpinski wrote:
Time it twice –
Thanks, using Float32 speeds up the code a bit:
*julia **function f1()*
*a=2.0*
*for i=1:100*
*a+=exp(a%2+1);*
*end*
*@printf %20.5e \n a*
*end*
*f1 (generic function with 1 method)*
*julia **@time f1()*
The log and exponential functions in Julia are about five times slower than
in C++. Is this reasonable?
Also log will throw a DomainErrror in Julia if you give it a negative
argument. That is another check and might prevent some optimizations.
onsdag 18. februar 2015 21.36.12 UTC+1 skrev Stefan Karpinski følgende:
What system are you on? And what libm are you using?
On Wed, Feb 18, 2015 at
Depends on how fast your system libm is – and how accurate. There's a
tradeoff.
On Wed, Feb 18, 2015 at 3:07 PM, Rohan Fernando rohanlu...@gmail.com
wrote:
The log and exponential functions in Julia are about five times slower
than in C++. Is this reasonable?
What system are you on? And what libm are you using?
On Wed, Feb 18, 2015 at 3:31 PM, Stefan Karpinski ste...@karpinski.org
wrote:
Depends on how fast your system libm is – and how accurate. There's a
tradeoff.
On Wed, Feb 18, 2015 at 3:07 PM, Rohan Fernando rohanlu...@gmail.com
wrote:
Maybe related https://github.com/JuliaLang/julia/issues/8869
2015-02-18 15:41 GMT-05:00 Ivar Nesje iva...@gmail.com:
Also log will throw a DomainErrror in Julia if you give it a negative
argument. That is another check and might prevent some optimizations.
onsdag 18. februar 2015 21.36.12
5x sounds like a lot. Maybe vectorized? However, as I remember it, the
relative timings depend quite a bit on the value of the argument.
2015-02-18 16:02 GMT-05:00 Stefan Karpinski ste...@karpinski.org:
None of the libm log and exp functions that are mentioned there have a 5x
performance
I ran both, Julia and C++, on Mac OS X 10.10.2.
Is that the information you asked for?
Thanks!
On Wednesday, February 18, 2015 at 2:32:23 PM UTC-6, Stefan Karpinski wrote:
Depends on how fast your system libm is – and how accurate. There's a
tradeoff.
On Wed, Feb 18, 2015 at 3:07 PM,
How did you do the timing?
On Wed, Feb 18, 2015 at 5:54 PM, Rohan Fernando rohanlu...@gmail.com
wrote:
I ran both, Julia and C++, on Mac OS X 10.10.2.
Is that the information you asked for?
Thanks!
On Wednesday, February 18, 2015 at 2:32:23 PM UTC-6, Stefan Karpinski
wrote:
Depends on
Not sure what libm is being used. How do I find out?
On Wednesday, February 18, 2015 at 2:36:12 PM UTC-6, Stefan Karpinski wrote:
What system are you on? And what libm are you using?
On Wed, Feb 18, 2015 at 3:31 PM, Stefan Karpinski ste...@karpinski.org
javascript: wrote:
Depends on how
It's probably the system libm for OS X which is one of the best around, but
not usually 5x faster than ours.
On Wed, Feb 18, 2015 at 5:58 PM, Rohan Fernando rohanlu...@gmail.com
wrote:
Not sure what libm is being used. How do I find out?
On Wednesday, February 18, 2015 at 2:36:12 PM UTC-6,
Here is the C++ code:
#include iostream
#include cmath
int main(int argc, const char * argv[]) {
srand (time(NULL));
clock_t t;
int a=2;
t = clock();
for (unsigned i=0; i100; i++) {
//a+=(log(a));
a+=exp(a%2);
//a+=(rand()%2+1);
Try wrapping the Julia code in a function and try again. The slow part is
incrementing `a` not the exp.
http://julia.readthedocs.org/en/latest/manual/performance-tips/#avoid-global-variables
On Wed, Feb 18, 2015 at 6:15 PM, Rohan Fernando rohanlu...@gmail.com
wrote:
Here is the C++ code:
Looks like it's the difference between log(x::Float64) and log(x::Real). I
had thought that an integer would be quickly converted to real.
On Wednesday, February 18, 2015 at 4:11:41 PM UTC-8, Peter Simon wrote:
Not sure why this is, but when I replace 2 with 2.0 in the first line of
the
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:100
a+=exp(a%2.0f32);
end
end
@time test1()
Julia elapsed time:
Any time you see a lot of bytes allocated in a function that shouldn't
allocate any, you have type instability problems. See the performance tips
page of the manual.
--Tim
On Wednesday, February 18, 2015 03:48:15 PM Rohan Fernando wrote:
Wrapped in function, but timing did not change.
On Wednesday, February 18, 2015 at 9:40:48 PM UTC-5, Kuba Roth wrote:
Interstingly Julia's example using Integer in mod operation is slower:
a+=exp(a%2);
elapsed time: 0.049916461 seconds (304116 bytes allocated)
div/rem/mod are currently slower in Julia than C++ because Julia performs
Thanks!
On Wednesday, February 18, 2015 at 6:11:41 PM UTC-6, Peter Simon wrote:
Not sure why this is, but when I replace 2 with 2.0 in the first line of
the function it seems to speed up by a factor of 8.
On Wednesday, February 18, 2015 at 3:48:15 PM UTC-8, Rohan Fernando wrote:
Wrapped
You should ignore the first run---functions in both `@time` and `f1` itself may
be being compiled. What is the comparison on the second run?
--Tim
On Wednesday, February 18, 2015 05:01:43 PM Rohan Fernando wrote:
Sorry, I used log in the earlier script. Now with a=2.0, C++ is only twice
as
Wrapped in function, but timing did not change.
function f1()
a=2
for i=1:100
a+=log(a%2+1);
end
a
end
@time f1()
output:
elapsed time: 0.151813773 seconds (64080600 bytes allocated, 15.55% gc time)
On Wednesday, February 18, 2015 at 5:19:21 PM UTC-6, Stefan
Also, in my testing, the allocated memory is vastly different:
julia @time f1()
elapsed time: 0.120954688 seconds (61 MB allocated, 1.51% gc time in 2
pauses with 0 full sweep)
2.0
julia function f2()
a=2.0
for i=1:100
a+=log(a%2+1.0);
end
Not sure why this is, but when I replace 2 with 2.0 in the first line of
the function it seems to speed up by a factor of 8.
On Wednesday, February 18, 2015 at 3:48:15 PM UTC-8, Rohan Fernando wrote:
Wrapped in function, but timing did not change.
function f1()
a=2
for i=1:100
Sorry, I used log in the earlier script. Now with a=2.0, C++ is only twice
as fast.
function f1()
a=2.0
for i=1:100
a+=exp(a%2+1);
end
a
end
@time f1()
elapsed time: 0.051447387 seconds (93896 bytes allocated)
On Wednesday, February 18, 2015 at 6:11:41 PM UTC-6,
24 matches
Mail list logo