-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Julia 3x slower than C on this I/O benchmark #2050
Comments
Note that unrolling the write loop in Julia does improve performance somewhat. The following code takes about 55 seconds: function bench2()
N = 10000
rows = ["row$i" for i in 1:N]
cols = ["col$i" for i in 1:N]
f = open("juliadump","w")
for i in 1:N
for j in 1:2:N
write(f,"$(rows[i]) $(cols[j])\n$(rows[i]) $(cols[j+1])\n")
end
end
close(f)
end |
Changing this line write(f,"$(rows[i]) $(cols[j])\n") to @printf(f, "%s %s\n", rows[i], cols[i]) brings down the timings to the same values of C (gcc with -O3) on my machine. |
As an alternative, this is even faster: write(f, rows[i])
write(f, " ")
write(f, cols[i]) On the other hand, using import Base.write
write(io::IO, x1, x...) = (write(io, x1); write(io, x...)) which is just as fast as the "manually unrolled" one above (but raises ambiguities currently, with write methods defined with |
I'm glad we can get to parity with C somehow but we clearly need to get all of these various ways of expressing this up to the same performance. |
Huge speedup, nice @carlobaldassi. I agree that this shouldn't be a gotcha though. |
Sorry, disregard my previous comment. The fastest option is |
1.1 times C, great!!! :) |
That is fantastic, thanks @carlobaldassi, really helps Miles and I out! |
It might be too much to expect this magic to happen without using a macro, but it should at least be documented. |
It could be made a lot closer in performance by not copying string data repeatedly while doing this (which is what the printf macro accomplishes). |
This seems like good info to go in the "Performance Tips" of the manual. |
Is this just a doc issue now? |
I still think we need to address the performance of the other ways of printing data. It's not really ok that there are some ways of printing things that are a performance trap while others are fast. |
Bumping to check if there is anything in here that should be captured in documentation or in performance tips. |
The original code now runs in 47 seconds for me, so now we're only 3x slower than C, updated title :) |
Probably the only way to make this faster is to use RopeString, but that still incurs an allocation so it may be the same speed, or slower. It's probably not possible to beat the multi-argument call to write (or equivalently |
Yes, RopeStrings are a disaster unless the strings you're concatenating are enormous. |
I now see a factor of 2 difference, and the same as C without string interp. I'll add a performance note and close this. |
where'd the extra factor go? having improved this by a factor of two (to a factor of two of C) is quite nice |
I got that number by writing to |
The following Julia code takes about 65 seconds on my machine:
The following C code takes about 15 seconds:
Seems like a good test of both memory thrashing and I/O. How can Julia's performance be improved?
The text was updated successfully, but these errors were encountered: