Install depot_tools
$ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
$ export PATH=`pwd`/depot_tools:"$PATH"
Build v8
$ fetch v8
{ | |
"metadata": { | |
"toolPackage": "@microsoft/api-extractor", | |
"toolVersion": "7.8.2-pr1796.0", | |
"schemaVersion": 1003, | |
"oldestForwardsCompatibleVersion": 1001 | |
}, | |
"kind": "Package", | |
"canonicalReference": "@google-cloud/video-intelligence!", | |
"docComment": "", |
'use strict'; | |
const Compute = require('@google-cloud/compute'); | |
const http = require('http'); | |
const compute = new Compute(); | |
const zone = compute.zone('us-central1-a'); | |
// Create a new VM, using default ubuntu image. The startup script |
const maxGap = (arr) => { | |
const n = arr.length; | |
let min = Number.POSITIVE_INFINITY; | |
let max = Number.NEGATIVE_INFINITY; | |
for (let i = 0; i < n; i++) { | |
min = Math.min(arr[i], min); | |
max = Math.max(arr[i], max); | |
} | |
let range = max - min; |
// Run `npm install @google-cloud/compute` first. | |
const Compute = require('@google-cloud/compute'); | |
const compute = new Compute(); | |
// Creates a new VM using the latest Ubuntu image. | |
(async () => { | |
try { | |
const zone = await compute.zone('us-central1-a'); | |
const data = await zone.createVM( | |
'ubuntu-instance', |
{ | |
"name": "profiler-issue", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "ISC", |
#include <napi.h> | |
#include <math.h> | |
namespace primes { | |
// Implementation of isPrime() and prime() omitted. See | |
// https://github.com/fhinkel/javascript-vs-native-addon-prime-numbers/blob/master/primes.cc | |
Napi::Value Method(const Napi::CallbackInfo& info) { | |
Napi::Env env = info.Env(); |
const js = require('./primes.js'); | |
const addon = require('./build/Release/primes.node'); | |
function run(i) { | |
console.time('Prime in js'); | |
js.prime(i); | |
console.timeEnd('Prime in js'); | |
console.time('Prime in addon'); | |
addon.prime(i); |
function isPrime(p) { | |
const upper = Math.sqrt(p); | |
for(let i = 2; i <= upper; i++) { | |
if (p % i === 0 ) { | |
return false; | |
} | |
} | |
return true; | |
} |
var fs = { | |
readFile: function(filename, cb) { | |
cb(null, {length: 12}); | |
} | |
} | |
for (var i = 0; i < 10000; i++) { | |
var __filename = 'perf-test.js'; | |
printLength(__filename) | |
} |