<commit_before>'use strict';

// MODULES //

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


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} len - array length
* @returns {Function} benchmark function
*/
function createBenchmark1( len ) {
	var x;
	var i;

	x = new Float64Array( len );
	for ( i = 0; i < x.length; i++ ) {
		x[ i ] = ( randu()*10000.0 ) - 20000.0;
	}
	return benchmark;

	/**
	* Benchmark function.
	*
	* @private
	* @param {Benchmark} b - benchmark instance
	*/
	function benchmark( b ) {
		var i;
		var j;

		b.tic();
		for ( i = 0; i < b.iterations; i++ ) {
			for ( j = 0; j < len; j++ ) {
				x[ j ] = ( randu()*10000.0 ) - 20000.0;
			}
			if ( isnan( x[ j ] ) ) {
				b.fail( 'should not return NaN' );
			}
		}
		b.toc();
		if ( isnan( x[ j ] ) ) {
			b.fail( 'should not return NaN' );
		}
		b.pass( 'benchmark finished' );
		b.end();
	} // end FUNCTION benchmark()
} // end FUNCTION createBenchmark1()

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} len - array length
* @returns {Function} benchmark function
*/
function createBenchmark2( len ) {
	var x;
	var i;

	x = new Float64Array( len );
	for ( i = 0; i < x.length; i++ ) {
		x[ i ] = ( randu()*10000.0 ) - 20000.0;
	}
	return benchmark;

	/**
	* Benchmark function.
	*
	* @private
	* @param {Benchmark} b - benchmark instance
	*/
	function benchmark( b ) {
		var nbytes;
		var heap;
		var v;
		var i;
		var j;

		nbytes = x.length * x.BYTES_PER_ELEMENT;
		heap = wasm.malloc( nbytes );
		heap.set( new Uint8Array( x.buffer ) );

		b.tic();
		for ( i = 0; i < b.iterations; i++ ) {
			for ( j = 0; j < len; j++ ) {
				v = ( randu()*10000.0 ) - 20000.0;
				heap.setValue( j * x.BYTES_PER_ELEMENT, v );
			}
			if ( isnan( v ) ) {
				b.fail( 'should not return NaN' );
			}
		}
		b.toc();
		if ( isnan( v ) ) {
			b.fail( 'should not return NaN' );
		}
		b.pass( 'benchmark finished' );

		wasm.free( heap );
		b.end();
	} // end FUNCTION benchmark()
} // end FUNCTION createBenchmark2()


// MAIN //

/**
* Main execution sequence.
*
* @private
*/
function main() {
	var len;
	var min;
	var max;
	var f;
	var i;

	min = 1; // 10^min
	max = 6; // 10^max

	for ( i = min; i <= max; i++ ) {
		len = pow( 10, i );

		f = createBenchmark1( len );
		bench( pkg+'::set-value,main:len='+len, f );

		f = createBenchmark2( len );
		bench( pkg+'::set-value,wasm:len='+len, f );
	}
} // end FUNCTION main()

main();<commit_msg>Add benchmarks for creating a separate view<commit_after>'use strict';

// MODULES //

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


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} len - array length
* @returns {Function} benchmark function
*/
function createBenchmark1( len ) {
	var x;
	var i;

	x = new Float64Array( len );
	for ( i = 0; i < x.length; i++ ) {
		x[ i ] = ( randu()*10000.0 ) - 20000.0;
	}
	return benchmark;

	/**
	* Benchmark function.
	*
	* @private
	* @param {Benchmark} b - benchmark instance
	*/
	function benchmark( b ) {
		var v;
		var i;
		var j;

		b.tic();
		for ( i = 0; i < b.iterations; i++ ) {
			for ( j = 0; j < len; j++ ) {
				v = ( randu()*10000.0 ) - 20000.0;
				x[ j ] = v;
			}
			if ( isnan( v ) ) {
				b.fail( 'should not return NaN' );
			}
		}
		b.toc();
		if ( isnan( v ) ) {
			b.fail( 'should not return NaN' );
		}
		b.pass( 'benchmark finished' );
		b.end();
	} // end FUNCTION benchmark()
} // end FUNCTION createBenchmark1()

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} len - array length
* @returns {Function} benchmark function
*/
function createBenchmark2( len ) {
	var x;
	var i;

	x = new Float64Array( len );
	for ( i = 0; i < x.length; i++ ) {
		x[ i ] = ( randu()*10000.0 ) - 20000.0;
	}
	return benchmark;

	/**
	* Benchmark function.
	*
	* @private
	* @param {Benchmark} b - benchmark instance
	*/
	function benchmark( b ) {
		var nbytes;
		var heap;
		var v;
		var i;
		var j;

		nbytes = x.length * x.BYTES_PER_ELEMENT;
		heap = wasm.malloc( nbytes );
		heap.set( new Uint8Array( x.buffer ) );

		b.tic();
		for ( i = 0; i < b.iterations; i++ ) {
			for ( j = 0; j < len; j++ ) {
				v = ( randu()*10000.0 ) - 20000.0;
				heap.setValue( j * x.BYTES_PER_ELEMENT, v );
			}
			if ( isnan( v ) ) {
				b.fail( 'should not return NaN' );
			}
		}
		b.toc();
		if ( isnan( v ) ) {
			b.fail( 'should not return NaN' );
		}
		b.pass( 'benchmark finished' );

		wasm.free( heap );
		b.end();
	} // end FUNCTION benchmark()
} // end FUNCTION createBenchmark2()

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} len - array length
* @returns {Function} benchmark function
*/
function createBenchmark3( len ) {
	var x;
	var i;

	x = new Float64Array( len );
	for ( i = 0; i < x.length; i++ ) {
		x[ i ] = ( randu()*10000.0 ) - 20000.0;
	}
	return benchmark;

	/**
	* Benchmark function.
	*
	* @private
	* @param {Benchmark} b - benchmark instance
	*/
	function benchmark( b ) {
		var nbytes;
		var heap;
		var view;
		var v;
		var i;
		var j;

		nbytes = x.length * x.BYTES_PER_ELEMENT;
		heap = wasm.malloc( nbytes );
		heap.set( new Uint8Array( x.buffer ) );

		view = new Float64Array( heap.buffer, heap.byteOffset, x.length );

		b.tic();
		for ( i = 0; i < b.iterations; i++ ) {
			for ( j = 0; j < len; j++ ) {
				v = ( randu()*10000.0 ) - 20000.0;
				view[ j ] = v;
			}
			if ( isnan( v ) ) {
				b.fail( 'should not return NaN' );
			}
		}
		b.toc();
		if ( isnan( v ) ) {
			b.fail( 'should not return NaN' );
		}
		b.pass( 'benchmark finished' );

		wasm.free( heap );
		b.end();
	} // end FUNCTION benchmark()
} // end FUNCTION createBenchmark3()


// MAIN //

/**
* Main execution sequence.
*
* @private
*/
function main() {
	var len;
	var min;
	var max;
	var f;
	var i;

	min = 1; // 10^min
	max = 6; // 10^max

	for ( i = min; i <= max; i++ ) {
		len = pow( 10, i );

		f = createBenchmark1( len );
		bench( pkg+'::set-value,main:len='+len, f );

		f = createBenchmark2( len );
		bench( pkg+'::set-value,wasm:len='+len, f );

		f = createBenchmark3( len );
		bench( pkg+'::set-value,wasm,view:len='+len, f );
	}
} // end FUNCTION main()

main();
{'fraction_non_alphanumeric': 0.18747203579418345, 'fraction_numerical': 0.026994780014914243, 'mean_word_length': 2.563230605738576, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6275207', 'n_tokens_mistral': 3072, 'n_tokens_neox': 2667, 'n_words': 723}