Skip to content

Commit

Permalink
v1.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolayMakhonin committed Dec 10, 2018
1 parent 46ab054 commit 70bae97
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 34 deletions.
11 changes: 6 additions & 5 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"extends": "standard",
"rules": {
"indent": ["error", "tab"],
"no-tabs": ["error", { allowIndentationTabs: true }]
}
"extends": "standard",
"rules": {
"indent": ["error", "tab"],
"no-tabs": ["error", { allowIndentationTabs: true }],
"no-trailing-spaces": ["off"]
}
}
6 changes: 6 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
1.2.2 / 2018-12-03
===================

* Improved calcPerformance function
* Removed dependencies

1.2.1 / 2018-12-03
===================

Expand Down
14 changes: 7 additions & 7 deletions binding.gyp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
'targets': [
{
'target_name': 'binding',
'defines': [ 'V8_DEPRECATION_WARNINGS=1' ],
'sources': [ 'src/binding.cc' ]
}
]
'targets': [
{
'target_name': 'binding',
'defines': [ 'V8_DEPRECATION_WARNINGS=1' ],
'sources': [ 'src/binding.cc' ]
}
]
}
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rdtsc",
"version": "1.2.1",
"version": "1.2.2",
"description": "The most high resolution cross platform timing in NodeJs that use processor command RDTSC. Calculate performance with accuracy +/- 4 processor cycles.",
"engines": {
"node": ">= 10.9.0"
Expand Down Expand Up @@ -54,7 +54,5 @@
"node-gyp": "^3.8.0",
"wavefile": "^8.4.4"
},
"dependencies": {
"ps-list": "^6.0.0"
}
"dependencies": {}
}
40 changes: 23 additions & 17 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,24 @@ const runInRealtimePriority = function (func) {
}

const calcPerformance = function (func0, func1, testTimeMilliseconds) {
let calcCount = (time, count) => {
return ~~Math.ceil(count * testTimeMilliseconds / (testTimeMilliseconds + time[0] * 1000 + time[1] / 1000000))
}

return runInRealtimePriority(() => {
let testTime = testTimeMilliseconds
let calcCount = (time, count) => {
return ~~Math.ceil(count * testTime / (testTime + time[0] * 1000 + time[1] / 1000000))
}

let f0 = func0
let f1 = func1
let m0 = mark0
let m1 = mark1
let m2 = mark2
let endTime = process.hrtime()
endTime[0] += ~~(testTimeMilliseconds / 1000)
endTime[1] += testTimeMilliseconds % 1000
endTime[0] += ~~(testTime / 1000)
endTime[1] += testTime % 1000

if (!func0 || !func1) {
func0 = func0 || func1
if (!func0) {
if (!f0 || !f1) {
f0 = f0 || f1
if (!f0) {
return undefined
}

Expand All @@ -67,9 +73,9 @@ const calcPerformance = function (func0, func1, testTimeMilliseconds) {
init()
let startCycles = rdtsc()
do {
mark0()
func0()
mark1()
m0()
f0()
m1()

i++
if (i >= count) {
Expand All @@ -95,11 +101,11 @@ const calcPerformance = function (func0, func1, testTimeMilliseconds) {
init()
let startCycles = rdtsc()
do {
mark0()
func0()
mark1()
func1()
mark2()
m0()
f0()
m1()
f1()
m2()

i++
if (i >= count) {
Expand Down
2 changes: 1 addition & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ describe('All tests', function () {
exception = ex
}

// console.log('Test exeption:');
// console.log('Test exception:');
// console.log(JSON.stringify(exception), exception.stack);

assert.ok(exception)
Expand Down

0 comments on commit 70bae97

Please sign in to comment.