This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var profiler = require('v8-profiler'); | |
var fs = require('fs'); | |
var processStartTime = new Date().getTime(); | |
profiler.startProfiling(); | |
while (true) { | |
rt.renderFrame(done); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var vector = { | |
make: function (x, y, z) { | |
if (x instanceof Array) { | |
return [x[0], x[1], x[2]]; | |
} else { | |
return [x, y, z]; | |
} | |
}, | |
dot: function (v, w) { | |
return (v[0] * w[0] + v[1] * w[1] + v[2] * w[2]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Vector(x, y, z) { | |
this.x = x; | |
this.y = y; | |
this.z = z; | |
} | |
Vector.prototype.dot = function(w) { | |
return this.x * w.x + this.y * w.y + this.z * w.z; | |
}; | |
// ... more vector functions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function add(a, b) { | |
return a + b; | |
} | |
add(1, 2); // Starts as monomorphic | |
add(2, 3); // Still monomorphic | |
add('x', 'y'); // Now becomes polymorphic - bad for optimisation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A reliable method to detect if we are running in Node.js | |
const isNodeJS = new Function('try {return this===global;}catch(e){return false;}')(); | |
var UniversalWorker; | |
var uri; | |
if (isNodeJS) { | |
// Dynamically load "workerjs" | |
UniversalWorker = require('workerjs'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... continuing from code above. | |
// We create the worker, the work can actally begin (but will give the | |
// worker a message to start later). | |
var worker = new UniversalWorker(uri); | |
// Listen to all messages from the worker. | |
worker.addEventListener('message', waitForResult, { once: true }); | |
// We send a message to the worker, this can be any primitive or object, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is our computation, we just initialise it for now. | |
var rt = new RayTracer(700, 700); | |
// we are in the worker.js thread so 'this' has the correct scope. | |
this.addEventListener('message', function(e) { | |
// Start the work | |
if (e.message === 'Start your work') { | |
var result = rt.raytrace(); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# This version uses September 2017 august stretch image, please use this image | |
# | |
if [ "$EUID" -ne 0 ] | |
then echo "Must be root" | |
exit | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
env: { | |
'es6': true, | |
'node': true, | |
}, | |
extends: 'airbnb-base', | |
plugins: ['jsdoc', 'prettier'], | |
rules: { | |
'prettier/prettier': 'error', |
OlderNewer