gpu.js/test/benchmark.js
Robert Plummer ef3f0cf001 feat: support for boolean as variable, argument, and constant
fix: implied else issue discovered, and fixed when testing boolean using leading and following return statements
fix: Added a section in documentation about types and added reference to boolean
fix: Bump and build
2019-04-29 08:45:43 -04:00

51 lines
1006 B
JavaScript

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