Elm Exactly
Results / elm-bytes /

BytesDecodeI32RoundtripTest

elm-0.19.1 passelm-0.19.2 passelm-0.19.3 passlamdera-1.5.0 pass
An Int encoded with `Bytes.Encode.unsignedInt32` big-endian decodes back to the same Int with `Bytes.Decode.unsignedInt32`.

The value is `0x12345678`. 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 47 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
BytesDecodeI32RoundtripTest: True

elm-0.19.2

passran in 72 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
BytesDecodeI32RoundtripTest: True

elm-0.19.3

passran in 59 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
BytesDecodeI32RoundtripTest: True

lamdera-1.5.0

passran in 55 ms
Output
BytesDecodeI32RoundtripTest: True

Discussions

Discuss this test·Search the discussions on GitHub

Discussions are on GitHub; one about this test has [t:elm-bytes/BytesDecodeI32RoundtripTest] in its title.

Source

The -- CHECK: lines give the expected output.

module BytesDecodeI32RoundtripTest exposing (main)
{-| An Int encoded with `Bytes.Encode.unsignedInt32` big-endian decodes back to the same Int with `Bytes.Decode.unsignedInt32`.
The value is `0x12345678`. 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: BytesDecodeI32RoundtripTest: True
import Bytes exposing (Bytes, Endianness(..))
import Bytes.Decode as D
import Bytes.Encode as E
import Html exposing (text)
main =
let
original : Int
original =
0x12345678
bytes : Bytes
bytes =
E.encode (E.unsignedInt32 BE original)
-- Allocation between encoding and decoding; the result is unused.
_ =
List.range 0 2000
|> List.map String.fromInt
|> String.concat
decoded : Int
decoded =
D.decode (D.unsignedInt32 BE) bytes
|> Maybe.withDefault -1
match : Bool
match =
decoded == original
_ =
Debug.log "BytesDecodeI32RoundtripTest" match
in
text (String.fromInt decoded)