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 Libraries Top

scohen
Lexical Lexical is a next-generation language server for the Elixir programming language. Features Context aware code completion As-you...
New
achempion
Hi, I would like to tell about my initiative to further maintain and develop Waffle project which is the fork of Arc library. The progre...
New
gabrielpoca
Hello everyone! I want to share with you something that I’m really proud of: https://stillstatic.io/ Still is a static site builder for...
New
mathieuprog
Hello :wave: Allow me to introduce you to Tz, an alternative time zone database support to Tzdata. Why another library? First and fore...
New
Crowdhailer
I have been updating a library that allows you to pipe between functions that use the erlang result tuple convention. Assuming you have...
New
benlime
LiveMotion enables high performance animations declared on the server and run on the client. As a follow up to my previous thread A libr...
New
mattludwigs
Grizzly is a library for working with Z-Wave devices. Z-Wave is a low-frequency radio protocol for controlling smart home devices on a me...
New
ostinelli
Let’s write a database! Well not really, but I think it’s a little sad that there doesn’t seem to be a simple in-memory distributed KV da...
New
tmbb
I’ve decided to create this topic to discuss optimization possibilities for something like Phoenix LiveView. I’ve created this topic unde...
New
mcrumm
If you would like to migrate away from node/npm/webpack while still using sass, the dart_sass package provides a installer and runner for...
New

Other popular topics Top

belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
yurko
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
New

Sub Categories:

We're in Beta

About us Mission Statement