Skip to content
Myr

Speed up bruteforce

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Andrey Sitnik · committed by Andrey Sitnik · parent 259da68 · Browse files · 1 file+13 added−14 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+13 added−14 removed

  • tests:+13 added−14 removed

1 file+13 added−14 removed

modified:test/bruteforce+13 added-14 removed
1#!/usr/bin/env node23var spawnSync = require('child_process').spawnSync3var sizeLimit = require('size-limit')4var chalk = require('chalk')5var path = require('path')6var fs = require('fs')77var filePath = process.argv[2]8var filePath = path.join(process.cwd(), process.argv[2])9var best = {10 value: '',11 size: Infinity12}
28 unmodified lines
41 fs.writeFileSync(filePath + '', result, 'utf8')42}4344function checkSize () {44 var output = spawnSync('npx', ['size-limit', filePath]).output45 var size = output.toString('utf8').match(/Package size: ([0-9]+)/)46 if (size && size[1] !== 0 && size[1] < best.size) {47 best.value = lastString48 best.size = size[1]49 process.stdout.write(chalk.green.bold(best.size) + 'B ' + best.value + '\n')50 }45 sizeLimit(filePath).then(function (size) {46 if (size.gzip < best.size) {47 best.value = lastString48 best.size = size.gzip49 process.stdout.write(50 chalk.green.bold(best.size + 'B') + ' ' + best.value + '\n')51 }52 shuffleStringInFile()53 checkSize()54 })55}5657saveFirstString()58if (typeof lastString === 'undefined') {59 process.stderr.write(chalk.red('Alphabet was not found') + '\n')60 process.exit(1)61}62checkSize()5960while (true) {61 shuffleStringInFile()62 checkSize()63}