• This repository has been archived on 18/Sep/2019
  • Stars
    star
    168
  • Rank 224,629 (Top 5 %)
  • Language
    JavaScript
  • Created about 14 years ago
  • Updated about 14 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Simple, easy, javascript benchmark testing

jslitmus: JavaScript benchmark testing made easy

jslitmus is copyright(C) Robert Kieffer, 2010. It is available for use under the MIT opensource license.

Examples

Better/richer examples are forthcoming. For now, checkout test/example.htm. It demonstrates how to setup and run tests, how to listen for test results, and how to get a google graph link for the results. (It even shows how to shorten that URL via bit.ly)

In a web page:

<script src="jslitmus.js"></script>
<script>
// Create a test to see how fast Array.join() is on 10K elements
var a = new Array(10000);
jslitmus.test('Join 10K elements', function() {
    a.join(' ');
});

// Log the test results
jslitmus.on('complete', function(test) {
    console.log(test);
});

// Run it!
jslitmus.runAll();
</script>

Outputs:

>>> Join 10K elements, f = 6.305khz (5.12k/0.812secs)

I.e. Our test function runs at a "frequency" of 6,305 times per second.

In a Node.js

var sys = require('sys');
var jslitmus = require('./jslitmus.js');

var a = new Array(10000);
jslitmus.test('Join 10K elements', function() {
    a.join(' ');
});

// Log the test results
jslitmus.on('complete', function(test) {
    sys.log(test);
});

// Run it!
jslitmus.runAll();

jslitmus API

In addition to the following, jslitmus also inherits the EventEmitter API, below.

Properties

  • Test - Class used to represent and evaluate a test function. See API docs below for more info.
  • unsupported.* - Methods that jslitmus implements for internal use, but that are useful enough to warrant exposing publically. But as the name says these will not be supported as part of the main jslitmus API. Use at your own risk.
  • platform - Platform detection information. Contains the following properties:
    • name - Common name (e.g. "Chrome", "IE", "Safari", "node")
    • version - Version string
    • os - Operating system, if known
    • description - String summarizing the above properties. (This is what the 'platform' object evaluates to when cast to a string, btw.)

Methods

  • test(name, function) - Add a test function
  • runAll() - Run all test functions added with jslitmus.test()
  • getGoogleChart() - Return a URL to a google chart image for all test results. Typically called as part of 'all_complete' event handling.

Events

  • all_complete() - Emitted after all tests have completed.
  • error(err) - Fires when an exception is thrown inside jslitmus.

Also, the following events are forwarded from any test created with jslitmus.test(). See the corresponding jslitmus.Test API event documentation for details:

  • complete(test)
  • error(err)
  • reset(test)
  • results(test)
  • start(test)

jslitmus.Test API

In addition to the following, jslitmus.Test also inherits the EventEmitter API, below.

Properties

  • INIT_COUNT - The initial iteration count to start with. There's not much reason to change this - jslitmus does a pretty good job of auto-calibrating. (default = 10)
  • MAX_COUNT - The maximum iteration count to allow. (default = 1e9)
  • MIN_TIME - The minimum a test run should take to be considered valid. (seconds, default = 1)
  • count - (read only) The number of iterations the test ran/will run for. (read only)
  • f - The test function. (read only)
  • isLoop - True if the test function is expected to provide it's own iteration loop. (read only)
  • name - The test name.
  • period - The 'period' of the test (time/iterations) (read only)
  • running - True if the test is in progress (read only)
  • time - The time taken to run the test (msecs, read only)

Methods

  • run(count, synchronous) - Run the test with the specified iteration count. If 'synchronous' is true this blocks until the test has completed, otherwise it's asynchronous.
  • getHz(normalize) - Get the frequency at which the test function can be run. If 'normalize' is true, jslitmus will attempt to subtract out the time invoved in doing the iteration loop (which can be significant when testing fast operations like "x++".)
  • bestOf(n) - Run the test n times, keeping the best result.
  • reset - Reset the test.
  • clone - Clone the test. The returned clone is reset() automatically.

Events

  • complete(test) - Fires when a test has been completed
  • error(err) - Fires if an exception is thrown inside a test
  • reset(test) - Fires when a test has been reset (e.g. in preparation for being run again)
  • results(test) - Fires when test results are available.
  • start(test) - Fires when a test has been started, before results are available. The test.count property indicates the number of iterations the test will be run for.

EventEmitter API

The EventEmitter API is not exposed directly - it is only available through jslitmus and jslitmus.Test objects that inherit it.

Properties

  • _emitting - The event currently being emitted

Methods

  • on(event, function) - Register a callback function for an event.
  • emit(event, ...) - Notify listeners of an event. All subsequent arguments are passed into listener functions.
  • removeListener(event, function) - Remove a previously registered callback function.
  • removeAllListeners(event) - Remove all registered callback functions.

More Repositories

1

mime

Mime types for JavaScript
TypeScript
2,157
star
2

BroofaJS

Misc. JS utilities that may be of broader interest
JavaScript
212
star
3

node-int64

Support for representing 64-bit integers in JavaScript
JavaScript
202
star
4

runmd

Executable markdown files
JavaScript
121
star
5

checkcss

TypeScript
27
star
6

joos

OO in JavaScript
JavaScript
18
star
7

simplur

TypeScript
14
star
8

jarvis

A Search Box Assistant
JavaScript
11
star
9

socipedia

A crowd-sourced business directory web app
PHP
9
star
10

jslife

Conway's Life Simulation, in JavaScript
HTML
6
star
11

proccoli

A customizable web proxy server
JavaScript
5
star
12

airjs

Javascript implementation of the barometric function for determining air density and pressure as a function of altitude
JavaScript
4
star
13

grout

A micro-framework for using CommonJS modules in browsers
3
star
14

mime-score

Logic for prioritizing MIME types based on facet, source, and type
TypeScript
3
star
15

jsscore

A debatable indicator of Javascript performance
JavaScript
3
star
16

jsciiart

Generate ascii art in realtime from webcamera in the browser using JavaScript + WebRTC (getUserMedia)
JavaScript
3
star
17

lzwjs

lzwjs
JavaScript
3
star
18

resnap

Simple API for capturing and resetting Node's require() cache state
JavaScript
3
star
19

plague

JavaScript
2
star
20

streamie

App for testing streaming transports in IE
JavaScript
2
star
21

flightcard

TypeScript
2
star
22

pek

A modern data model for UI rendering
JavaScript
2
star
23

storagehooks

JavaScript
1
star
24

perf-lite

Lightweight language performance test
C++
1
star
25

gmaul

TypeScript
1
star
26

stringlang

Utility functions for analyzing strings by Unicode block
JavaScript
1
star
27

oshareport

The Oregon OSHA report form, reskinned for COVID enforcement
HTML
1
star
28

thrustcurve-db

JavaScript
1
star