1.4.3 • Published 10 years ago

tinytic v1.4.3

Weekly downloads
3
License
MIT
Repository
github
Last release
10 years ago

tinytic

Description

Tiny and easy to use module for getting time differences, especially useful for animation.

Installation

Either use npm:

npm i -S tinytic

Or include minified file in your project to attach tinytic to the window.

API

toc: returns the time difference in milliseconds since toc was last called. Takes an optional argument which specifies the maximum time difference that will be returned. This is a good idea when using requestAnimationFrame as the browser may stop requesting frames (e.g. if the user has switched tabs) and produce an excessive time difference.

total: returns the total time elapsed either since tinytic was first loaded or since reset was last called.

reset: sets tinytic to its initialized state resetting all timers.

Example

var tinytic = require('tinytic');

//optionally set maximum time difference in milliseconds
var maxDT = 500;

function render (dT, totalTimeElapsed) {
  // ...
}

function loop() {
  requestAnimationFrame(loop);
  var dT = tinytic.toc(maxDT);
  //if no maximum time difference is required then use as below:
  //var dT = tinytic.toc();

  //if total time elapsed is required use as below:
  var totalTimeElapsed = tinytic.total();
  render(dT, totalTimeElapsed);
}

loop();

Implementation

In order of preference tinytic measures time using performance.now, Date.now, or new Date().getTime, so it should work in virtually any JS environment.

1.4.3

10 years ago

1.4.2

10 years ago

1.4.1

10 years ago

1.4.0

10 years ago

1.3.2

10 years ago

1.3.1

10 years ago

1.3.0

10 years ago

1.2.5

10 years ago

1.2.4

10 years ago

1.2.3

10 years ago

1.2.2

10 years ago

1.2.1

10 years ago

1.2.0

10 years ago

1.1.3

10 years ago

1.1.2

10 years ago

1.1.1

10 years ago

1.1.0

11 years ago

1.0.1

11 years ago

1.0.0

11 years ago