/*Math.exp(logBase * exponent);  // fastest
Math.exp(Math.log(base) * exponent);  // middle
Math.pow(base, exponent);  // slowest
*/

'use strict'

/* pow vs math.exp
 *
 * despite claims to the contrary (http://stackoverflow.com/questions/17891595/pow-vs-exp-performance)
 * Math.pow is clearly the fastest, at least in node.js.
 *
 */ 


let Benchmark = require( 'benchmark' )

let suite = new Benchmark.Suite;

module.exports = function() {

let foo = function( p0 ) {
  return Math.pow( p0, 3 )
}
foo.floor = Math.floor

let bar = function( p0 ) {
    return Math.exp( Math.log(p0), 3 )
}

let baz = function() {
  return Math.exp( 3,3 )
}

// add tests
suite.add( 'using Math.pow', function() {
  foo( Math.random() * 30 )
})
.add( 'Using Math.exp( Math.log(base), exponent)', function() {
  bar( Math.random() * 30 )
})
.add( 'Using Math.exp( static base, exponent)', function() {
  baz( Math.random() * 30 )
})

.on( 'cycle', function(event) {
  console.log(String(event.target));
})
.on( 'complete', function() {
  console.log('Fastest is ' + this.filter('fastest').map('name'));
})
.run({ 'async': true });

}
