Julia vs C++-11 for random walks

440 views
Skip to first unread message

lapeyre....@gmail.com

unread,
Jan 5, 2015, 9:56:07 AM1/5/15
to julia...@googlegroups.com
Hi, here is a comparison of Julia and C++ for simulating a random walk.

It is the first Julia program I wrote. I just pushed it to github.

--John

lapeyre....@gmail.com

unread,
Jan 5, 2015, 10:12:51 AM1/5/15
to julia...@googlegroups.com
Oh, and, (I forgot to mention!)  the Julia code runs much faster.

Isaiah Norton

unread,
Jan 5, 2015, 10:50:56 AM1/5/15
to julia...@googlegroups.com
Very neat. Just in case this gets posted to the interwebz, it is worth pointing out that the performance advantage for Julia can probably be explained by differences in the underlying RNG. We use dsFMT, which is known to be one of (if not the?) fastest MT libraries around. I could not find any published comparisons in a quick google, but based on this test harness [1], dsFMT may be significantly faster than std::mt19937:

```
ihnorton@julia:~/tmp/cpp-random-test$ ./random-real
C++11 : 2.34846
Boost : 0.371674
dSFMT : 0.281255
GSL   : 0.649981
```

lapeyre....@gmail.com

unread,
Jan 5, 2015, 11:11:45 AM1/5/15
to julia...@googlegroups.com
 It may be in part the implementation of the RNG. I think it is also in part whether the abstraction is optimized away.
Notice that Julia v0.3 is faster than v0.4. This is probably randbool() vs. rand(Bool).

Viral Shah

unread,
Jan 5, 2015, 2:59:02 PM1/5/15
to julia...@googlegroups.com
I doubt that rand(Bool) is any slower, since randbool() calls rand(Bool). It is worth filing this as a performance regression.

-viral

lapeyre....@gmail.com

unread,
Jan 5, 2015, 3:23:08 PM1/5/15
to julia...@googlegroups.com
I meant randbool() in v0.3, where it was a more direct call, not randbool() in v0.4.
Anyway, I just found the problem and patched it. Adding one '@inline' now makes rand(Bool) in v0.4
about as fast as randbool() in v0.3.

Should I open an issue (bug report), or just make a PR ?

Viral Shah

unread,
Jan 5, 2015, 3:25:18 PM1/5/15
to julia...@googlegroups.com
Thanks. Do create a PR.

-viral

lapeyre....@gmail.com

unread,
Jan 5, 2015, 3:50:43 PM1/5/15
to julia...@googlegroups.com
Ok. It's done.  Just to be sure I understood what I read on a github forum; there is no way for me to attach a label to the PR. So the labels are always added by someone else ?

--John

Viral Shah

unread,
Jan 5, 2015, 3:52:58 PM1/5/15
to julia...@googlegroups.com
I believe the labels can only be attached by those who have read/write access.

-viral

lapeyre....@gmail.com

unread,
Jan 5, 2015, 3:58:15 PM1/5/15
to julia...@googlegroups.com
Good. This is fine with me.Thanks.
--John

Frank Kampas

unread,
Jan 6, 2015, 9:20:59 AM1/6/15
to julia...@googlegroups.com
Microsoft C code is not very fast these days.  You might want to compare with MinGW.
Reply all
Reply to author
Forward
0 new messages