【发布时间】:2021-10-04 07:25:52
【问题描述】:
我这里有个问题:
function main()
b = UInt8[0x35, 0x30, 0x2e, 0x30] # This is "50.0" in bytes
s = parse(Float64, String(b))
end
@btime main()
250.269 ns (2 allocations: 128 bytes)
50.0
我有一个 UInt8 数组,其中包含一个字符串格式的数字,例如“50.0”。我想尽可能快地将这个数字解析成一个没有分配的浮点数(我有数百万个这样的数字要解析)。有没有比我上面生成的方法更好的方法(忽略 UInt8 数组的分配,因为这将不存在)。
干杯!
【问题讨论】:
标签: performance julia heap-memory allocation