TimeEveryZeroIntervalTest
`Time.every` with a zero, negative or infinite interval ticks at a bounded rate rather than as fast as it can. The program subscribes to `Time.every 0`, `Time.every -5` and `Time.every (1 / 0)` for 200 ms, then unsubscribes and reports. Each must have ticked at most 400 times, twice what one tick per millisecond would give, and the zero interval must have ticked at least once.
Results
elm-0.19.1
passran in 243 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets. (node:31377) TimeoutOverflowWarning: Infinity does not fit into a 32-bit signed integer. Timeout duration was set to 1. (Use `node --trace-warnings ...` to show where the warning was created) zero: "zero bounded: True" zero: "negative bounded: True" zero: "inf bounded: True" zero: "zero ticked: True"
elm-0.19.2
passran in 242 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets. (node:60681) TimeoutOverflowWarning: Infinity does not fit into a 32-bit signed integer. Timeout duration was set to 1. (Use `node --trace-warnings ...` to show where the warning was created) zero: "zero bounded: True" zero: "negative bounded: True" zero: "inf bounded: True" zero: "zero ticked: True"
elm-0.19.3
passran in 259 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets. (node:90143) TimeoutOverflowWarning: Infinity does not fit into a 32-bit signed integer. Timeout duration was set to 1. (Use `node --trace-warnings ...` to show where the warning was created) zero: "zero bounded: True" zero: "negative bounded: True" zero: "inf bounded: True" zero: "zero ticked: True"
lamdera-1.5.0
passran in 249 msOutput
(node:118972) TimeoutOverflowWarning: Infinity does not fit into a 32-bit signed integer. Timeout duration was set to 1. (Use `node --trace-warnings ...` to show where the warning was created) zero: "zero bounded: True" zero: "negative bounded: True" zero: "inf bounded: True" zero: "zero ticked: True"
Discussions
Discuss this test·Search the discussions on GitHub
Discussions are on GitHub; one about this test has [t:elm-time/TimeEveryZeroIntervalTest] in its title.
Source
The -- CHECK: lines give the expected output.
module TimeEveryZeroIntervalTest exposing (main)
{-| `Time.every` with a zero, negative or infinite interval ticks at a bounded rate rather than as
fast as it can.
The program subscribes to `Time.every 0`, `Time.every -5` and `Time.every (1 / 0)` for 200 ms,
then unsubscribes and reports. Each must have ticked at most 400 times, twice what one tick per
millisecond would give, and the zero interval must have ticked at least once.
-}
-- MODE-GUARD: a Char equality must give the same answer as under --optimize
-- NO-SKIP: an edge case every compiler must run
-- CHECK: zero: "zero bounded: True"
-- CHECK: zero: "negative bounded: True"
-- CHECK: zero: "inf bounded: True"
-- CHECK: zero: "zero ticked: True"
import Platform
import Process
import Task
import Time
type Msg
= Z Time.Posix
| N Time.Posix
| I Time.Posix
| Stop
type alias Model =
{ z : Int
, n : Int
, i : Int
, stopped : Bool
}
init : () -> ( Model, Cmd Msg )
init _ =
( { z = 0, n = 0, i = 0, stopped = False }
, Task.perform (\_ -> Stop) (Process.sleep 200)
)
bool : Bool -> String
bool v =
if v then
"True"
else
"False"
bound : Int
bound =
400
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
Z _ ->
( { model | z = model.z + 1 }, Cmd.none )
N _ ->
( { model | n = model.n + 1 }, Cmd.none )
I _ ->
( { model | i = model.i + 1 }, Cmd.none )
Stop ->
let
_ =
Debug.log "zero" ("zero bounded: " ++ bool (model.z <= bound))
_ =
Debug.log "zero" ("negative bounded: " ++ bool (model.n <= bound))
_ =
Debug.log "zero" ("inf bounded: " ++ bool (model.i <= bound))
_ =
Debug.log "zero" ("zero ticked: " ++ bool (model.z >= 1))
in
( { model | stopped = True }, Cmd.none )
subscriptions : Model -> Sub Msg
subscriptions model =
if model.stopped then
Sub.none
else
Sub.batch
[ Time.every 0 Z
, Time.every -5 N
, Time.every (1 / 0) I
]
main : Program () Model Msg
main =
Platform.worker
{ init = init
, update = update
, subscriptions = subscriptions
}