'use strict';

// MODULES //

var randu = require( '@stdlib/math/base/random/randu' );
var isnan = require( '@stdlib/math/base/utils/is-nan' );
var expm1 = require( './../lib' );


// VARIABLES //

var N = 1e7;


// FUNCTIONS //

function warmup() {
	var i;
	var j;

	j = 0;
	for ( i = 0; i < 1e6; i++ ) {
		j += i * 2;
	}
	if ( j > 0 ) {
		return true;
	}
	return false;
}

function test( name, fcn ) {
	var start;
	var time;
	var bool;
	var x;
	var y;
	var i;

	bool = warmup();
	if ( !bool ) {
		throw new Error( 'Something went wrong.' );
	}
	start = process.hrtime();
	for ( i = 0; i < N; i++ ) {
		x = randu()*10.0 - 5.0;
		y = fcn( x );
		if ( isnan( y ) ) {
			throw new Error( 'Something went wrong.' );
		}
	}
	time = process.hrtime( start );
	time = time[ 0 ] + time[ 1 ]*1.0e-9;

	if ( isnan( y ) ) {
		throw new Error( 'Something went wrong.' );
	}
	console.log( 'Test: %s. Elapsed time: %d sec. Iterations: %d. ops/s: %d.', name, time, N, N/time );
}

function benchmark() {
	if ( typeof Math.expm1 === 'function' ) {
		test( 'Math.expm1', Math.expm1 );
		test( 'Math.expm1', Math.expm1 );
		test( 'Math.expm1', Math.expm1 );
	}
	test( 'expm1', expm1 );
	test( 'expm1', expm1 );
	test( 'expm1', expm1 );
}


// MAIN //

benchmark();

@@ -19,24 +19,64 @@
 MODULES //%0A%0A
+var bench = require( '@stdlib/bench' );%0A
 var randu = 
@@ -173,24 +173,71 @@
 /is-nan' );%0A
+var pkg = require( './../package.json' ).name;%0A
 var expm1 = 
@@ -286,52 +286,114 @@
 var 
-N = 1e7;%0A%0A%0A// FUNCTIONS //%0A%0Afunction warmup(
+opts = %7B%0A%09'skip': ( typeof Math.expm1 !== 'function' )%0A%7D;%0A%0A%0A// MAIN //%0A%0Abench( pkg, function benchmark( b 
 ) %7B%0A
@@ -401,26 +401,36 @@
 var 
-i
+x
 ;%0A%09var 
-j;%0A%0A%09j = 0
+y;%0A%09var i;%0A%0A%09b.tic()
 ;%0A%09f
@@ -449,284 +449,350 @@
 i %3C 
-1e6; i++ ) %7B%0A%09%09j += i * 2;%0A%09%7D%0A
+b.iterations; i++ ) %7B%0A%09%09x = ( randu()*10.0 ) - 5.0;%0A%09%09y = expm1( x );%0A%09
 %09if ( 
-j %3E 0 ) %7B%0A%09%09return true;%0A%09%7D%0A%09return false;%0A%7D%0A%0Afunction test( name, fcn ) %7B%0A%09var start;%0A%09var time;%0A%09var bool;%0A%09var x;%0A%09var y;%0A%09var i;%0A%0A%09bool = warmup();%0A%09if ( !bool ) %7B%0A%09%09throw new Error( 'Something went wrong.' );%0A%09%7D%0A%09start = process.hrtime
+isnan( y ) ) %7B%0A%09%09%09b.fail( 'should not return NaN' );%0A%09%09%7D%0A%09%7D%0A%09b.toc();%0A%09if ( isnan( y ) ) %7B%0A%09%09b.fail( 'should not return NaN' );%0A%09%7D%0A%09b.pass( 'benchmark finished' );%0A%09b.end();%0A%7D);%0A%0Abench( pkg+'::native', opts, function benchmark( b ) %7B%0A%09var x;%0A%09var y;%0A%09var i;%0A%0A%09b.tic
 ();%0A
@@ -809,17 +809,28 @@
  0; i %3C 
-N
+b.iterations
 ; i++ ) 
@@ -836,16 +836,18 @@
  %7B%0A%09%09x =
+ (
  randu()
@@ -851,16 +851,18 @@
 u()*10.0
+ )
  - 5.0;%0A
@@ -871,11 +871,18 @@
 y = 
-fcn
+Math.expm1
 ( x 
@@ -913,582 +913,164 @@
 %0A%09%09%09
-throw new Error( 'Something went wrong.' );%0A%09%09%7D%0A%09%7D%0A%09time = process.hrtime( start );%0A%09time = time%5B 0 %5D + time%5B 1 %5D*1.0e-9;%0A%0A%09if ( isnan( y ) ) %7B%0A%09%09throw new Error( 'Something went wrong.' );%0A%09%7D%0A%09console.log( 'Test: %25s. Elapsed time: %25d sec. Iterations: %25d. ops/s: %25d.', name, time, N, N/time );%0A%7D%0A%0Afunction benchmark() %7B%0A%09if ( typeof Math.expm1 === 'function' ) %7B%0A%09%09test( 'Math.expm1', Math.expm1 );%0A%09%09test( 'Math.expm1', Math.expm1 );%0A%09%09test( 'Math.expm1', Math.expm1 );%0A%09%7D%0A%09test( 'expm1', expm1 );%0A%09test( 'expm1', expm1 );%0A%09test( 'expm1', expm1 );%0A%7D%0A%0A%0A// MAIN //%0A%0Abenchmark(
+b.fail( 'should not return NaN' );%0A%09%09%7D%0A%09%7D%0A%09b.toc();%0A%09if ( isnan( y ) ) %7B%0A%09%09b.fail( 'should not return NaN' );%0A%09%7D%0A%09b.pass( 'benchmark finished' );%0A%09b.end();%0A%7D
 );%0A

Add benchmark