BytesDecodeFloat64RoundtripTest
A Float encoded with `Bytes.Encode.float64` little-endian decodes back to exactly the same Float. The value is `3.141592653589793`. Between encoding and decoding the program builds and concatenates about two thousand strings, so the bytes are decoded after other allocation has happened. The logged `True` is the equality check.
Results
elm-0.19.1
passran in 53 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets. BytesDecodeFloat64RoundtripTest: True
elm-0.19.2
passran in 58 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets. BytesDecodeFloat64RoundtripTest: True
elm-0.19.3
passran in 56 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets. BytesDecodeFloat64RoundtripTest: True
lamdera-1.5.0
passran in 53 msOutput
BytesDecodeFloat64RoundtripTest: True
Discussions
Discuss this test·Search the discussions on GitHub
Discussions are on GitHub; one about this test has [t:elm-bytes/BytesDecodeFloat64RoundtripTest] in its title.
Source
The -- CHECK: lines give the expected output.
module BytesDecodeFloat64RoundtripTest exposing (main)
{-| A Float encoded with `Bytes.Encode.float64` little-endian decodes back to exactly the same Float.
The value is `3.141592653589793`. Between encoding and decoding the program
builds and concatenates about two thousand strings, so the bytes are decoded after
other allocation has happened. The logged `True` is the equality check.
-}
-- CHECK: BytesDecodeFloat64RoundtripTest: True
import Bytes exposing (Bytes, Endianness(..))
import Bytes.Decode as D
import Bytes.Encode as E
import Html exposing (text)
main =
let
original : Float
original =
3.141592653589793
bytes : Bytes
bytes =
E.encode (E.float64 LE original)
-- Allocation between encoding and decoding; the result is unused.
_ =
List.range 0 2000
|> List.map String.fromInt
|> String.concat
decoded : Float
decoded =
D.decode (D.float64 LE) bytes
|> Maybe.withDefault 0.0
match : Bool
match =
decoded == original
_ =
Debug.log "BytesDecodeFloat64RoundtripTest" match
in
text (String.fromFloat decoded)