User Timing/Performance, grasp.
// Начало замера var startTime = new Date; slowFunction(); // Время выполнения var duration = (new Date) - startTime;
console.time/timeEnd,
но они только выводитят результат в консоль.
new Date есть один существенный недостаток.
Если замеряемый участок кода выполнется в пределах 1ms,
продолжительность такого участка получится 0ms.
performance.now,
который возвращает DOMHighResTimeStamp.
{
name: "foo", // название записи
entryType: "mark", // тип записи
startTime: 2686782.357000047, // время засечки
duration: 0 // всегда ноль, т.к. это засечка
}
{
name: "foo_bar", // название записи
entryType: "measure", // тип записи
startTime: 2686782.357000047, // время последней засечки
duration: 7876.608999911696 // продолжительность
}
<head>
<script>performance.mark("head_start");<script>
...
<script>
performance.mark("head_end");
performance.measure("head", "head_start", "head_end");
<script>
<head>
<body>
<script>performance.mark("body_start");<script>
...
<script>
performance.mark("body_end");
performance.measure("body", "body_start", "body_end");
<script>
<body>
var entries = performance.getEntriesByType("measure");
var i = entries.length;
while( i-- ){
var entry = entries[i];
__monitoring("page", entry.name, entry.duration);
}
Если у вас нет своего мониторинга, то вы всегда можете использовать Google Analytics:
function __monitoring(category, name, duration){
duration = Math.round(duration);
(window._gaq || (window._gaq = []))
.push(["_trackTiming", category, name, duration]);
}
performance.mark("body__end");
performance.measure("body", "body_start", "body_end");
performance.markEnd = function (name){
performance.mark("_" + name);
performance.measure(name, name, "_" + name);
};
толькоИнтсрумент для поиска и рефакторинга JavaScript кода на основе его структуры, а не текста.
Устанавливаем: npm install -g grasp
api.edit = function (action, items, extra, callback){
//* __ *//
};
api.edit = function (params/**Object*/){
//* __ *//
};
grasp -r -e 'api.edit(_$)' path/to
path/to/foo.js:37 api.edit("remove", [1, 2])
path/to/sub/bar.js:3 api.edit("mark", ids)
path/to/baz.js:3 api.edit("more", list, extra, callback)
grasp -r -e 'api.edit($a, $i)'
-R 'api.edit({ action: {{a}}, items: {{i}} })'
path/to -i
grasp -r -e 'api.edit($a, $i, $e, $c)'
-R 'api.edit({ action: {{a}}, items: {{i}}, extra: {{e}}, callback: {{c}} })'
path/to -i