Skip to content

Parsing as Float32 half as fast as parsing as Float64 and converting to Float32 #37662

Closed
@Luapulu

Description

@Luapulu

So, I just discovered this:

julia> using BenchmarkTools
julia> @btime parse(Float64, "50.303")
  32.163 ns (0 allocations: 0 bytes)
50.303

julia> @btime parse(Float32, "50.303")
  71.524 ns (0 allocations: 0 bytes)
50.303f0

julia> @btime convert(Float32, parse(Float64, "50.303"))
  32.430 ns (0 allocations: 0 bytes)
50.303f0

If parsing as Float64 and converting to Float32 is twice as fast, why not do it that way by default?

I googled around a bit and couldn't find anything on this so hopefully I'm not missing something obvious here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions