Package Exports
- rdtsc
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (rdtsc) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Description
The most high resolution timing in NodeJs
This module provide function rdtsc() that call C++ function __rdtsc() that call processor command RDTSC (Read Time Stamp Counter)
rdtsc() return counts the number of cycles since computer start
(rdtsc() - rdtsc()) is always < 0
Tested on Windows
Install
npm i rdtsc -SFeatures
RDTSC
var { rdtsc } = require('rdtsc');
console.log(rdtsc()); // 3864063236708616 cycles
console.log(rdtsc() - rdtsc()); // -2971 cyclesCacl Performance
Syntax
calcPerformance(func0, func1, testTimeMilliseconds);
// result = <min time of func1> - <min time of func0>;
calcPerformance(null, func1, testTimeMilliseconds);
// result = <min time of func1>;
calcPerformance(func0, null, testTimeMilliseconds);
// result = <min time of func0>Example
var { calcPerformance } = require('rdtsc');
var result = calcPerformance(
() => {
},
() => {
Object.keys(Math);
},
1000);
console.log('"Object.keys(Math)" min cycles =', result); //about 20-40 cyclesThread Prioriies
Implemented only for Windows platform
Example
const { setThreadPriority, getThreadPriority, isWin, THREAD_PRIORITY_TIME_CRITICAL } = require('rdtsc');
if (isWin) {
console.log(getThreadPriority()); // === THREAD_PRIORITY_NORMAL
} else {
console.log(getThreadPriority()); // === undefined
}
var previousPriority = setThreadPriority(THREAD_PRIORITY_TIME_CRITICAL);
try {
<your code>
} finally {
setThreadPriority(previousPriority);
}Priorities list
const THREAD_PRIORITY_IDLE = -15;
const THREAD_PRIORITY_LOWEST = -2;
const THREAD_PRIORITY_BELOW_NORMAL = -1;
const THREAD_PRIORITY_NORMAL = 0;
const THREAD_PRIORITY_ABOVE_NORMAL = 1;
const THREAD_PRIORITY_HIGHEST = 2;
const THREAD_PRIORITY_TIME_CRITICAL = 15;