Skip to content

Use a faster (more time efficient) data structure for clock.timers #159

@akhilkedia

Description

@akhilkedia

Summary
Right now, clock.timers in Lolex is an array, which is looped through completely everytime in firstTimer() or LastTimer().
This is extremely inefficient, and perhaps other data structures such as a heap might be much faster.

Background Details
Lolex is great for running simulations - but in one of my recent projects, I attempted to use Lolex to run a code over a simulated period of 1 week - the code made a LOT of setTimeouts, and these were all handled by Lolex.

Profiling the code showed the majority of my simulation runtime was spent in Lolex's firstTimer() function, because it kept looping through a long array of timers everytime.

Changing clock.timers to a simple heap fixed this performance bottleneck.

Since Lolex is targeted primarily towards running simulations/tests, being able to run them faster will be great.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions