'use strict';

// MODULES //

var randu = require( '@stdlib/math/base/random/randu' );
var round = require( '@stdlib/math/base/special/round' );
var isnan = require( '@stdlib/math/base/utils/is-nan' );
var cos = 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 = round( randu()*10000.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() {
	test( 'Math.cos', Math.cos );
	test( 'cos', cos );

	test( 'Math.cos', Math.cos );
	test( 'cos', cos );

	test( 'Math.cos', Math.cos );
	test( 'cos', cos );
}


// MAIN //

benchmark();

@@ -27,21 +27,21 @@
 //%0A%0Avar 
-randu
+bench
  = requi
@@ -57,30 +57,13 @@
 lib/
-math/base/random/randu
+bench
 ' );
@@ -68,20 +68,20 @@
 );%0Avar r
-ou
+a
 nd
+u
  = requi
@@ -107,21 +107,20 @@
 ase/
-special/rou
+random/ra
 nd
+u
 ' );
@@ -181,19 +181,19 @@
  );%0Avar 
-cos
+pkg
  = requi
@@ -206,83 +206,111 @@
 /../
-lib' );%0A%0A%0A// VARIABLES //%0A%0Avar N = 1e7;%0A%0A%0A// FUNCTIONS //%0A%0Afunction warmup(
+package.json' ).name;%0Avar cos = require( './../lib' );%0A%0A%0A// MAIN //%0A%0Abench( pkg, function benchmark( b 
 ) %7B%0A
@@ -318,322 +318,391 @@
 var 
-i
+x
 ;%0A%09var 
-j;%0A%0A%09j = 0;%0A%09for ( i = 0; i %3C 1e6; i++ ) %7B%0A%09%09j += i * 2;%0A%09%7D%0A%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
+y;%0A%09var i;%0A%0A%09b.tic();%0A%09for ( i = 0; i %3C b.iterations; i++ ) %7B%0A%09%09x = ( randu()*20.0 ) - 10.0;%0A%09%09y = cos( x );%0A%09%09if ( 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', function benchmark( b ) %7B%0A%09var x;%0A%09var y;%0A%09var i;%0A%0A%09b.tic
 ();%0A
@@ -719,17 +719,28 @@
  0; i %3C 
-N
+b.iterations
 ; i++ ) 
@@ -751,13 +751,8 @@
 x = 
-round
 ( ra
@@ -761,25 +761,29 @@
 u()*
-1000
+2
 0.0 )
+ - 10.0
 ;%0A%09%09y = 
 fcn(
@@ -782,11 +782,16 @@
 y = 
-fcn
+Math.cos
 ( x 
@@ -822,511 +822,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%09test( 'Math.cos', Math.cos );%0A%09test( 'cos', cos );%0A%0A%09test( 'Math.cos', Math.cos );%0A%09test( 'cos', cos );%0A%0A%09test( 'Math.cos', Math.cos );%0A%09test( 'cos', cos );%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

Update benchmarks