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 · GitHub
various-benchmarks-erlang/test/bench_microtimer_send_after.erl at main · d-led/various-benchmarks-erlang · GitHub

Where Next?

Popular in Announcing Top

wmnnd
Hi there, for my project DBLSQD, I needed a file storage solution that is a bit more flexible than Arc. Because I thought others might f...
New
wfgilman
I’ve cleaned up and open sourced three financial libraries I was using for my company. They are bindings for the APIs of these three comp...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 30380 241
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 44608 311
New
sasajuric
I’d like to announce a small library called boundaries. This is an experimental project which explores the idea of enforcing boundaries ...
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 11241 107
New
martinthenth
Hello everybody :wave: Recently, some of my colleagues talked about database ids and uuids and their problems, and I remembered the pain...
New

Other popular topics Top

grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 54092 488
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
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
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

We're in Beta

About us Mission Statement