-
-
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
performance of cat of scalars of mixed types #4467
Comments
This does not address the request per se, but an alternate syntax is ar = Float64[a, b, c, d, e] How does the performance of this compare with your second code block? |
Ah, thanks. ( @JeffBezanson had actually mentioned something like that too, which I forgot.) The performance is nearly the same as the second block of code (maybe 1-2% slower, although my tests were limited so this is probably like 2% plus or minus 3%.) That syntax is much nicer than my second block of code, but I'd still request optimization of the other case as well. |
I started looking at this. If a,b,c,d,e are all the same type, then the two versions ( |
Ah that makes sense. One of the variables was an integer. |
will not have full effect until _oldstyle_array_vcat_ is turned off.
These now both take the same time (30 ns) using the function below function f()
a, b, c, d, e = 1.0, 2.0, 3.0, 4.0, 5.0
println(@benchmark ar = [$a, $b, $c, $d, $e])
println(@benchmark begin ar = Array{Float64}(5)
ar[1]=$a
ar[2]=$b
ar[3]=$c
ar[4]=$d
ar[5]=$e
end)
end |
The performance of
is much worse than the performance of
where a-e are Float64's because the former syntax uses the cat operation (for a good reason, as explained by @JeffBezanson - a-e could be many things including arrays etc., which makes the "bracket" syntax require an extremely dynamic operation (i.e., cat) in the general case).
This is a request to analyze constructs in the "bracket" notation (i.e., the first example above) and optimize the creation of the array in cases where the types of the elements can be determined statically. For example, translate the first block of code to the second internally, or do something more optimal.
(Changing the [ ] code to manually declare and assign arrays as above in our code increases speed by about 25% currently. However, the syntax is undesirable in our context from a readability standpoint.)
The text was updated successfully, but these errors were encountered: