Elm Exactly
Results / elm-bytes /

BytesWidthOfSliceTest

elm-0.19.1 passelm-0.19.2 passelm-0.19.3 passlamdera-1.5.0 pass
`Bytes.width` of the `Bytes` value that `Bytes.Decode.bytes 40` takes from a 50-byte buffer
is 40.

The buffer is 50 bytes of 7.

Results

elm-0.19.1

passran in 49 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
slice_width: 40

elm-0.19.2

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

elm-0.19.3

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

lamdera-1.5.0

passran in 66 ms
Output
slice_width: 40

Discussions

Discuss this test·Search the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

module BytesWidthOfSliceTest exposing (main)
{-| `Bytes.width` of the `Bytes` value that `Bytes.Decode.bytes 40` takes from a 50-byte buffer
is 40.
The buffer is 50 bytes of 7.
-}
-- CHECK: slice_width: 40
import Bytes exposing (Bytes, Endianness(..))
import Bytes.Decode as D
import Bytes.Encode as E
import Html exposing (text)
main =
let
buffer =
E.encode (E.sequence (List.repeat 50 (E.unsignedInt8 7)))
sliceWidth =
D.decode (D.bytes 40) buffer
|> Maybe.map Bytes.width
|> Maybe.withDefault -1
_ =
Debug.log "slice_width" sliceWidth
in
text "done"