Skip to content

Instantly share code, notes, and snippets.

@subtleGradient
Last active October 4, 2019 17:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save subtleGradient/97dc65290f1ce06a6eb4b2151d5a2557 to your computer and use it in GitHub Desktop.
Save subtleGradient/97dc65290f1ce06a6eb4b2151d5a2557 to your computer and use it in GitHub Desktop.
git bisect script for checking if flow is slow
#!/usr/bin/env node --experimental-modules
/* eslint-disable no-console */
import { execSync } from 'child_process';
process.env.ROOT_VIEW_PATH = `src/common/components/views/RootView.js`;
const exec = script => {
console.log(`$ ${script}`);
execSync(script, { stdio: 'inherit' });
};
function timeToFunFlow() {
const startTime = Date.now();
exec(`npm run flow`);
const endTime = Date.now();
const timeItTook = endTime - startTime;
return timeItTook;
}
// execSync(`npm run flow -- stop`, { stdio: 'inherit' });
const coldStart = timeToFunFlow();
const noChanges = timeToFunFlow();
exec(`
cat "$ROOT_VIEW_PATH" > "$ROOT_VIEW_PATH.bak"
echo '// IGNORE THIS' >> "$ROOT_VIEW_PATH"
`);
const afterChangingAFile = timeToFunFlow();
exec(`
cat "$ROOT_VIEW_PATH.bak" > "$ROOT_VIEW_PATH"
rm "$ROOT_VIEW_PATH.bak"
`);
console.log(`Time it took to run flow:`, {
coldStart,
noChanges,
afterChangingAFile
});
if (afterChangingAFile > 30000) {
throw new Error(`expected flow to be fast, but it wasn't`);
}
@subtleGradient
Copy link
Author

./scripts/flow-is-fast.node.mjs && echo 'win' || echo 'fail'

@subtleGradient
Copy link
Author

Only weird thing (so far!) about using the #!/usr/bin/env node --experimental-modules trick is that __dirname doesn't exist.
weird! But not weird enough to waste time figuring out why 🤷‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment