gpu.js/test/benchmark.js
Robert Plummer 82e4966551 feat: v2.0.0rc1
Cleanup and add random support (seeded by... Math.random()!)
I went through api and cleaned it up considerably
2019-01-31 18:24:25 -05:00

50 lines
928 B
JavaScript

const GPU = require('../src/index.js');
const Benchmark = require('benchmark');
const suite = new Benchmark.Suite();
const gpuRunner = new GPU({ mode: 'webgl' });
const cpuRunner = new GPU({ mode: 'cpu' });
const size = 2048;
// SIMPLE
const myGPUFunc = gpuRunner
.createKernel(function compute() {
const i = this.thread.x;
const j = 0.89;
return i + j;
})
.setPipeline(true)
.setOutput([size, size]);
const myCPUFunc = cpuRunner
.createKernel(function compute() {
const i = this.thread.x;
const j = 0.89;
return i + j;
})
.setOutput([size, size]);
// add tests
suite
.add('gpu', () => {
myGPUFunc();
})
.add('cpu', () => {
myCPUFunc();
})
// add listeners
.on('cycle', function(event) {
console.log(String(event.target));
})
.on('complete', () => {
console.log('Fastest is ' + this.filter('fastest').map('name'));
})
.run({ 'async': true });