time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

precision.js (1676B)


      1 /**
      2 * @license Apache-2.0
      3 *
      4 * Copyright (c) 2018 The Stdlib Authors.
      5 *
      6 * Licensed under the Apache License, Version 2.0 (the "License");
      7 * you may not use this file except in compliance with the License.
      8 * You may obtain a copy of the License at
      9 *
     10 *    http://www.apache.org/licenses/LICENSE-2.0
     11 *
     12 * Unless required by applicable law or agreed to in writing, software
     13 * distributed under the License is distributed on an "AS IS" BASIS,
     14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     15 * See the License for the specific language governing permissions and
     16 * limitations under the License.
     17 */
     18 
     19 'use strict';
     20 
     21 // TODO: clean-up
     22 
     23 // MODULES //
     24 
     25 var divide = require( 'compute-divide' );
     26 var mean = require( 'compute-mean' );
     27 var subtract = require( 'compute-subtract' );
     28 var abs = require( './../../../../base/special/abs' );
     29 var sqrt = require( './../lib' );
     30 
     31 
     32 // FIXTURES //
     33 
     34 var data = require( './fixtures/julia/data.json' );
     35 
     36 
     37 // MAIN //
     38 
     39 var customErrs;
     40 var nativeErrs;
     41 var yexpected;
     42 var ycustom;
     43 var ynative;
     44 var x;
     45 var i;
     46 
     47 x = data.x;
     48 yexpected = data.expected;
     49 ycustom = new Array( x.length );
     50 ynative = new Array( x.length );
     51 for ( i = 0; i < x.length; i++ ) {
     52 	if ( yexpected[ i ] === 0.0 ) {
     53 		yexpected[ i ] += 1e-16;
     54 	}
     55 	ycustom[ i ] = sqrt( x[ i ] );
     56 	ynative[ i ] = Math.sqrt( x[ i ] );
     57 }
     58 
     59 customErrs = abs( divide( subtract( ycustom, yexpected ), yexpected ) );
     60 nativeErrs = abs( divide( subtract( ynative, yexpected ), yexpected ) );
     61 
     62 console.log( 'The mean relative error of Math.sqrt compared to Julia is %d', mean( nativeErrs ) );
     63 console.log( 'The mean relative error of this module compared to Julia is %d', mean( customErrs ) );