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
const { MessageChannel, Worker } = require('worker_threads'); | |
const worker = new Worker('./worker.js'); | |
const benchmarkChannel = new MessageChannel(); | |
worker.postMessage({ port: benchmarkChannel.port2 }, [ benchmarkChannel.port2 ]); | |
(function run() { | |
for (let i = 0; i < 1000000; i += 1) { | |
benchmarkChannel.port1.postMessage('hello world'); | |
} |
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
const { Readable } = require('stream'); | |
const ITEM_COUNT = 10 * 1000 * 1000; | |
class EventStream extends Readable { | |
constructor(count) { | |
super({ objectMode: true }); | |
this.remainingCount = count; | |
} |
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 try1() { | |
try { | |
return 1; | |
} catch (error) { | |
} finally { | |
console.log('try1(): in finally{}'); | |
} | |
} |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Library test</title> | |
</head> | |
<body> | |
<p id="datetime"></p> | |
<script src="dist/main.js"></script> | |
<script> | |
function displayTime() { |
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
'use strict'; | |
function findPairs(inputs) { | |
const unpairedNumbers = new Set(); | |
const pairs = []; | |
for (let element of inputs) { | |
if (unpairedNumbers.has(element)) { | |
pairs.push(element); | |
unpairedNumbers.delete(element); | |
} else { |
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
'use strict'; | |
const pg = require('pg'); | |
const PG_URL = process.env.PG_URL || 'postgres://postgres:postgres@127.0.0.1/postgres'; | |
const ITERATIONS = Number(process.env.ITERATIONS || 10); | |
const VARIANT = Number(process.env.VARIANT || 0); | |
async function benchmarkPg() { | |
const client = new pg.Client({ | |
connectionString: PG_URL |
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
'use strict'; | |
const http = require('http'); | |
http.request = function fakeRequest() { | |
console.log('faked!'); | |
}; |
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
<!DOCTYPE html PUBLIC> | |
<html> | |
<head> | |
<title>Root window</title> | |
</head> | |
<body> | |
<p id="greeter">Nothing here yet...</p> | |
<button id="opener">Open a new window</button> | |
<script> | |
window.greet = function greet() { |
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
'use strict'; | |
const Big = require('big.js'); | |
const EventEmitter = require('events'); | |
/** | |
* An EventEmitter that emits subsequent approximations of number Pi. | |
* @extends external:EventEmitter | |
*/ | |
class PiEmitter extends EventEmitter { |
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
* firing query | |
* query result: 1 | |
* firing query | |
* query result: 1 | |
* firing query | |
* query result: 1 | |
* firing query | |
* query result: 1 | |
* firing query | |
* query result: 1 |
NewerOlder