Very well, I shall do things to make it not read 1ns:
Trial 1 : Assigning rand()
values and wrapping in a function:
julia> @btime (()->begin x=(a=rand(),b=rand(),c=rand(),d=rand(),e=rand(),f=rand(),g=rand(),h=rand())
ns=propertynames(x)
NamedTuple{ns}(map(n->getproperty(x,n), ns))
end)()
24.121 ns (0 allocations: 0 bytes)
(a = 0.5218322278054724, b = 0.6490145188159838, c = 0.4498112605320129, d = 0.2697056519272063, e = 0.6922591013353949, f = 0.5024083965138986, g = 0.45278375949414684, h = 0.24272686573005509)
julia> @btime (()->begin x=(a=rand(),b=rand(),c=rand(),d=rand(),e=rand(),f=rand(),g=rand(),h=rand())
ns=propertynames(x)
NamedTuple{ns}(getproperty(x,n) for n β ns)
end)()
1.570 ΞΌs (35 allocations: 1.28 KiB)
(a = 0.6107745757701861, b = 0.5396769758183816, c = 0.8256041605409281, d = 0.23232080960554702, e = 0.8874158525617497, f = 0.4739403505021156, g = 0.02362650987609838, h = 0.7094814751186344)
julia> @btime (()->begin x=(a=rand(),b=rand(),c=rand(),d=rand(),e=rand(),f=rand(),g=rand(),h=rand())
ns=propertynames(x)
NamedTuple{ns}(((getproperty(x,n) for n β ns)...,))
end)()
24.197 ns (0 allocations: 0 bytes)
(a = 0.03819138796796251, b = 0.6413247235460257, c = 0.261317462471773, d = 0.5650563667359987, e = 0.7155291639741849, f = 0.6288825770558325, g = 0.2565432038568122, h = 0.4965357876488232)
Trial 2 : using @time
instead of @btime
:
julia> @time for _=1:1_000_000 (()->begin x=(a=rand(),b=rand(),c=rand(),d=rand(),e=rand(),f=rand(),g=rand(),h=rand())
ns=propertynames(x)
NamedTuple{ns}(map(n->getproperty(x,n), ns))
end)() end
0.230494 seconds (4.04 M allocations: 139.845 MiB, 13.44% gc time, 15.24% compilation time)
julia> @time for _=1:1_000_000 (()->begin x=(a=rand(),b=rand(),c=rand(),d=rand(),e=rand(),f=rand(),g=rand(),h=rand())
ns=propertynames(x)
NamedTuple{ns}(getproperty(x,n) for n β ns)
end)() end
1.537471 seconds (38.07 M allocations: 1.286 GiB, 7.40% gc time, 1.83% compilation time)
julia> @time for _=1:1_000_000 (()->begin x=(a=rand(),b=rand(),c=rand(),d=rand(),e=rand(),f=rand(),g=rand(),h=rand())
ns=propertynames(x)
NamedTuple{ns}(((getproperty(x,n) for n β ns)...,))
end)() end
0.210565 seconds (4.05 M allocations: 140.694 MiB, 13.43% gc time, 16.36% compilation time)
It appears that order-of-magnitude differences persist.
Edit:
Trial 3: Using a list comprehension to populate an array with these:
julia> @time [begin x=(a=rand(),b=rand(),c=rand(),d=rand(),e=rand(),f=rand(),g=rand(),h=rand())
ns=propertynames(x)
NamedTuple{ns}(map(n->getproperty(x,n), ns))
end for _=1:1_000_000];
0.050902 seconds (64.67 k allocations: 65.224 MiB, 6.23% gc time, 58.25% compilation time)
julia> @time [begin x=(a=rand(),b=rand(),c=rand(),d=rand(),e=rand(),f=rand(),g=rand(),h=rand())
ns=propertynames(x)
NamedTuple{ns}(getproperty(x,n) for n β ns)
end for _=1:1_000_000];
0.929006 seconds (35.10 M allocations: 1.288 GiB, 7.40% gc time, 6.24% compilation time)
julia> @time [begin x=(a=rand(),b=rand(),c=rand(),d=rand(),e=rand(),f=rand(),g=rand(),h=rand())
ns=propertynames(x)
NamedTuple{ns}(((getproperty(x,n) for n β ns)...,))
end for _=1:1_000_000];
0.053575 seconds (78.28 k allocations: 66.077 MiB, 8.75% gc time, 57.46% compilation time)