Skip to content

Commit

Permalink
Merge 0cf5e55 into 060dcf3
Browse files Browse the repository at this point in the history
  • Loading branch information
hcodes committed Jan 8, 2023
2 parents 060dcf3 + 0cf5e55 commit 86f7e4e
Show file tree
Hide file tree
Showing 372 changed files with 7,642 additions and 11,543 deletions.
3 changes: 0 additions & 3 deletions .babelrc

This file was deleted.

1 change: 1 addition & 0 deletions .eslintignore
Expand Up @@ -4,3 +4,4 @@ build/**
dist/**
node_modules/**
test/**
*.config.js
81 changes: 0 additions & 81 deletions .eslintrc

This file was deleted.

9 changes: 9 additions & 0 deletions .eslintrc.js
@@ -0,0 +1,9 @@
module.exports = {
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
]
};
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -5,7 +5,8 @@ node_modules/
coverage/
test/fixtures/before/*.tmp
npm-debug.log
benchmark/*.txt
benchmark/*.html
benchmark/books/*.html
src/version.ts
.DS_Store
.vscode
3 changes: 3 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,8 @@
# Changelog

# v7.0.0
- Перевод кодовой базы на TypeScript.

# v6.16.0
- Обновлены dev-зависимости в package.json.
- Удалена сборка на основе Gulp.
Expand Down
2 changes: 1 addition & 1 deletion README.md
@@ -1,4 +1,4 @@
Типограф на JavaScript
Типограф
======================
<img align="right" width="200" src="https://avatars0.githubusercontent.com/u/10176019" />

Expand Down
65 changes: 0 additions & 65 deletions benchmark/benchmark.js

This file was deleted.

71 changes: 71 additions & 0 deletions benchmark/benchmark.mjs
@@ -0,0 +1,71 @@
import fs from 'fs';
import Typograf from '../build/typograf.es.mjs';

const typograf = new Typograf({ locale: 'ru' });
const beforeTimes = {};
const resultTimes = {};
const text = fs.readFileSync('./benchmark/books/war_and_peace.html').toString();

typograf.onBeforeRule = function(name) {
beforeTimes[name] = now();
};
typograf.onAfterRule = function(name) {
resultTimes[name] = (resultTimes[name] || 0) + now() - beforeTimes[name];
};

function now() {
const hrtime = process.hrtime();
return (hrtime[0] * 1000000 + hrtime[1] / 1000) / 1000;
}

function formatNumber(num) {
return num.toFixed(3);
}

function calcTimes() {
const times = [];
let total = 0;

Object.keys(resultTimes).forEach(name => {
times.push({
name,
time: resultTimes[name],
});
});

times.sort((a, b) => {
if (a.time < b.time) {
return 1;
} else if (a.time > b.time) {
return -1;
}

return 0;
});

times.forEach(function(item) {
total += item.time;
});

return {
times,
total,
};
}

console.log(`Text length: ${text.length} symbols`);

const startTime = now();

const output = typograf.execute(text);

const totalTime = now() - startTime;
console.log(`Total time: ${formatNumber(totalTime)} ms`);

const result = calcTimes();
console.log(`\nTime in rules: ${formatNumber(result.total)} ms`);
result.times.forEach((item, i) => {
console.log(`${i + 1}. ${item.name}: ${formatNumber(item.time)} ms`);
});

fs.writeFileSync('./benchmark/output.html', output);

0 comments on commit 86f7e4e

Please sign in to comment.