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

kip
Image is an image processing library for Elixir. It is based upon the fabulous vix library that provides a libvips wrapper for Elixir. I...
574 16576 179
New
devonestes
Introducing assertions, the library that helps you write really great test assertions! GitHub: https://github.com/devonestes/assertions ...
New
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
benlime
I created a new library GitHub - benvp/ex_cva: Class Variance Authority for Elixir which aims to make it very easy to define different va...
New
tfwright
After working on it for a couple of months and using it in production for most of that time, today I’ve released LiveAdmin, a LiveView ba...
New
tmbb
I’ve published the first version of my Makeup library. It’s a syntax highlighter for Elixir in the spirit of Pygments, Currently it highl...
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 27727 240
New
ericlathrop
I built a silly site for Halloween that uses Phoenix Channels on the backend, and React on the frontend. I had many problems integrating ...
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

Other popular topics Top

chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30048 115
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
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 49522 488
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
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 42633 214
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
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
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New

Sub Categories:

We're in Beta

About us Mission Statement