'use strict';

// MODULES //

var isnan = require( '@stdlib/math/base/utils/is-nan' );
var randu = require( '@stdlib/math/base/random/randu' );
var atanh = 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()*2.0 - 1.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.atanh === 'function' ) {
		test( 'Math.atanh', Math.atanh );
		test( 'Math.atanh', Math.atanh );
		test( 'Math.atanh', Math.atanh );
	}
	test( 'atanh', atanh );
	test( 'atanh', atanh );
	test( 'atanh', atanh );
}


// MAIN //

benchmark();

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/math/base/random/randu' );
var isnan = require( '@stdlib/math/base/utils/is-nan' );
var pkg = require( './../package.json' ).name;
var atanh = require( './../lib' );


// VARIABLES //

var opts = {
	'skip': ( typeof Math.atanh !== 'function' )
};


// MAIN //

bench( pkg, function benchmark( b ) {
	var x;
	var y;
	var i;

	b.tic();
	for ( i = 0; i < b.iterations; i++ ) {
		x = ( randu()*2.0 ) - 1.0;
		y = atanh( x );
		if ( isnan( y ) ) {
			b.fail( 'should not return NaN' );
		}
	}
	b.toc();
	if ( isnan( y ) ) {
		b.fail( 'should not return NaN' );
	}
	b.pass( 'benchmark finished' );
	b.end();
});

bench( pkg+'::native', opts, function benchmark( b ) {
	var x;
	var y;
	var i;

	b.tic();
	for ( i = 0; i < b.iterations; i++ ) {
		x = ( randu()*2.0 ) - 1.0;
		y = Math.atanh( x );
		if ( isnan( y ) ) {
			b.fail( 'should not return NaN' );
		}
	}
	b.toc();
	if ( isnan( y ) ) {
		b.fail( 'should not return NaN' );
	}
	b.pass( 'benchmark finished' );
	b.end();
});

Update benchmarks