massimo

massimo

MicroTimer - A Timer module with microsecond resolution

Hello,
I’ve just released MicroTimer a Timer module with microsecond resolution.

It allows you to sleep for as low as it takes to the Beam to send a message (usually around 3-5 μs).

It also contains function to send messages or run functions after a timeout or repeatedly every timeout μs.

Beware that the system sleep does nothing when it’s waiting and consumes no CPU, while this functions may waste CPU cycles for a maximum of 2ms every call.

It’s usually not a big deal, but it’s better to consider it.

The main reason this library was born is to sync with uneven frequencies that cannot be expressed in integer milliseconds.

One example is game loops that run at 60 FPS (it’s 16.667ms or 16,667μs every frame), if you use plain integers you have to use 16ms, which is 62.5FPS, or you have to use different timeouts (for example 56 frames of 17ms + 4 of 16ms) that could make the experience annoying, depending on the type of game.

The system sleep is also a lot less precise: in my measurements the system function had a std deviation of around 2,200μs (2.2ms), while MicroTimer.sleep std deviation was 16μs (0.016ms) for the same dataset.

Check out the bench folder to see how the times were taken or run your own tests.

First Post!

d-led

d-led

great stuff! Reminded me of my childhood experiments with a more precise sleep.
Did a small benchmark that runs on Github: GitHub - d-led/various-benchmarks-erlang
various-benchmarks-erlang/test/bench_microtimer_send_after.erl at main · d-led/various-benchmarks-erlang · GitHub

Where Next?

Popular in Announcing Top

dominicletz
Hi, I thought I had posted my library before but seems I hadn’t. The project is still in early stages but it’s growing and so I think it...
New
Crowdhailer
The latest release of Ace (0.10.0) includes serving content over HTTP/2. I have started writing a webserver to teach my self more about...
New
jakub-zawislak
Hi everyone, I’m coming from the Symfony (PHP) framework. I like Phoenix, but it has a one thing that was build much better in the Symfo...
New
Qqwy
Today I realized that it would be possible to implement currying-capability in Elixir, using some clever anonymous function creation. ('c...
New
blatyo
https://www.conduitframework.com/ The best overview for how things are tied together is this presentation. Modules and functions are pre...
New
Azolo
Hey everyone, I just released WebSockex which is a Elixir WebSocket client. WebSockex strives to work as a OTP special process, be RFC6...
New
kelvinst
Hey everyone! Well, we made this lib a while ago and now we decided to finally go out and public with it! It’s a tool for creating and m...
New
Crowdhailer
Raxx is an alternative to Plug and is inspired by projects such as Rack(Ruby) and Ring(Clojure). 1.0-rc.1 is now available. To use it re...
New
markmark206
simple_feature_flags is a tiny package that lets you turn features on or off based on which environment (e.g. localhost, staging, product...
New
trisolaran
Hi! :waving_hand: I would like to present LiveSelect, a little library that I wrote to easily add a dynamic selection input to your LV f...
198 10836 107
New

Other popular topics Top

Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 43591 214
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
hariharasudhan94
Lets say i have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => "XX...
New

We're in Beta

About us Mission Statement