Skip to content

Commit

Permalink
add explicit encoding for perf measurements
Browse files Browse the repository at this point in the history
  • Loading branch information
gnoff committed Apr 8, 2022
1 parent 105a28e commit 550fb61
Showing 1 changed file with 173 additions and 4 deletions.
177 changes: 173 additions & 4 deletions fixtures/fizz/server/render-to-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,186 @@ import * as React from 'react';
import {renderToString} from 'react-dom/server';
import App from '../src/App';
import {API_DELAY, ABORT_DELAY} from './delays';
import {performance} from 'perf_hooks';

// In a real setup, you'd read it from webpack build stats.
let assets = {
'main.js': '/main.js',
'main.css': '/main.css',
};

let textEncoder = new TextEncoder();

module.exports = function render(url, res) {
res.send(
let payload =
'<!DOCTYPE html>' +
renderToString(<App assets={assets} />) +
'<script src="/main.js" async=""></script>'
);
renderToString(<App assets={assets} />) +
'<script src="/main.js" async=""></script>';
let start = performance.now();
let arr = textEncoder.encode(payload);
let end = performance.now();
console.log('single block encoding elapsed -- ', end - start);

// let from, increment, parts;

// // --- increment 1
// increment = 1;
// parts = [];
// from = 0;
// for (let i = 0; i < increment; i++) {
// let to = Math.ceil((payload.length / increment) * (i + 1));
// parts.push(payload.slice(from, to));
// from = to;
// }

// start = performance.now();
// for (let i = 0; i < parts.length; i++) {
// let part = parts[i];
// textEncoder.encode(part);
// // Buffer.from(part);
// }
// end = performance.now();
// console.log(`${increment} block encoding elapsed -- ${end - start}`);

// start = performance.now();
// for (let i = 0; i < parts.length; i++) {
// let part = parts[i];
// }
// end = performance.now();
// console.log(`${increment} block no encoding elapsed -- ${end - start}`);

// // --- increment 10
// increment = 10;
// parts = [];
// from = 0;
// for (let i = 0; i < increment; i++) {
// let to = Math.ceil((payload.length / increment) * (i + 1));
// parts.push(payload.slice(from, to));
// from = to;
// }

// start = performance.now();
// for (let i = 0; i < parts.length; i++) {
// let part = parts[i];
// textEncoder.encode(part);
// // Buffer.from(part);
// }
// end = performance.now();
// console.log(`${increment} block encoding elapsed -- ${end - start}`);

// start = performance.now();
// for (let i = 0; i < parts.length; i++) {
// let part = parts[i];
// }
// end = performance.now();
// console.log(`${increment} block no encoding elapsed -- ${end - start}`);

// // --- increment 100
// increment = 100;
// parts = [];
// from = 0;
// for (let i = 0; i < increment; i++) {
// let to = Math.ceil((payload.length / increment) * (i + 1));
// parts.push(payload.slice(from, to));
// from = to;
// }

// start = performance.now();
// for (let i = 0; i < parts.length; i++) {
// let part = parts[i];
// textEncoder.encode(part);
// // Buffer.from(part);
// }
// end = performance.now();
// console.log(`${increment} block encoding elapsed -- ${end - start}`);

// start = performance.now();
// for (let i = 0; i < parts.length; i++) {
// let part = parts[i];
// }
// end = performance.now();
// console.log(`${increment} block no encoding elapsed -- ${end - start}`);

// // --- increment 1,000
// increment = 1000;
// parts = [];
// from = 0;
// for (let i = 0; i < increment; i++) {
// let to = Math.ceil((payload.length / increment) * (i + 1));
// parts.push(payload.slice(from, to));
// from = to;
// }

// start = performance.now();
// for (let i = 0; i < parts.length; i++) {
// let part = parts[i];
// textEncoder.encode(part);
// // Buffer.from(part);
// }
// end = performance.now();
// console.log(`${increment} block encoding elapsed -- ${end - start}`);

// start = performance.now();
// for (let i = 0; i < parts.length; i++) {
// let part = parts[i];
// }
// end = performance.now();
// console.log(`${increment} block no encoding elapsed -- ${end - start}`);

// // --- increment 10,000
// increment = 10000;
// parts = [];
// from = 0;
// for (let i = 0; i < increment; i++) {
// let to = Math.ceil((payload.length / increment) * (i + 1));
// parts.push(payload.slice(from, to));
// from = to;
// }

// start = performance.now();
// for (let i = 0; i < parts.length; i++) {
// let part = parts[i];
// textEncoder.encode(part);
// // Buffer.from(part);
// }
// end = performance.now();
// console.log(`${increment} block encoding elapsed -- ${end - start}`);

// start = performance.now();
// for (let i = 0; i < parts.length; i++) {
// let part = parts[i];
// }
// end = performance.now();
// console.log(`${increment} block no encoding elapsed -- ${end - start}`);

// // --- increment 100,000
// increment = 100000;
// parts = [];
// from = 0;
// for (let i = 0; i < increment; i++) {
// let to = Math.ceil((payload.length / increment) * (i + 1));
// parts.push(payload.slice(from, to));
// from = to;
// }

// start = performance.now();
// for (let i = 0; i < parts.length; i++) {
// let part = parts[i];
// textEncoder.encode(part);
// // Buffer.from(part);
// }
// end = performance.now();
// console.log(`${increment} block encoding elapsed -- ${end - start}`);

// start = performance.now();
// for (let i = 0; i < parts.length; i++) {
// let part = parts[i];
// }
// end = performance.now();
// console.log(`${increment} block no encoding elapsed -- ${end - start}`);

let buf = Buffer.from(arr);
res.statusCode = 200;
res.setHeader('Content-type', 'text/html');
res.send(buf);
};

0 comments on commit 550fb61

Please sign in to comment.