Skip to content

Commit

Permalink
fixed perf tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim de Beer committed Jul 24, 2016
1 parent 792cc31 commit 266e0d8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
5 changes: 2 additions & 3 deletions lib/keys/sort/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ exports.add = function add (target, key, filtered, index) {
} else if (len === keys.length) {
filtered.splice(index, 0, key)
} else {
// this can go faster prob by using a lookup backwards in the keys array
// then you jnow where to watch and you only have one while loop
let left = -1
let i = index - 1
while (left === -1 && i) {
Expand Down Expand Up @@ -43,6 +41,7 @@ exports.add = function add (target, key, filtered, index) {
filtered.push(key)
}
}

// this funciton is retarded
exports.sort = function sort (target, keys, index, newIndex) {
// want some kind of diff...
Expand All @@ -67,5 +66,5 @@ exports.sort = function sort (target, keys, index, newIndex) {
exports.update = function update (target, key, index, newIndex) {
const parent = target.cParent()
exports.sort(parent, parent._keys, index, newIndex)
// dont really need update funciton here....
// dont really need update funciton here.... -- just call sort
}
18 changes: 8 additions & 10 deletions test/performance/keys.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'
const Base = require('../../')
const test = require('vigour-performance')
var amount = 10
var amount = 3e3

// function createBase () {
// for (let i = 0; i < amount; i++) {
Expand Down Expand Up @@ -74,7 +74,7 @@ function setKeysRandom () {
const b = new a.Constructor({ key: 'ITS B' })
b.keys()
for (let i = 0; i < amount; i++) {
b.set({ [i % 2 ? i + 'e' : i]: ~~(Math.random() * amount) })
b.set({ [i % 5 ? i + 'e' : i]: ~~(Math.random() * amount) })
}
}

Expand All @@ -85,7 +85,7 @@ function orderedKeysRandom () {
b.keys()
for (let i = 0; i < amount; i++) {
b.set({
[i % 2 ? i + 'e' : i]: {
[i % 5 ? i + 'e' : i]: {
order: ~~(Math.random() * amount)
}
})
Expand All @@ -109,7 +109,7 @@ function orderedKeysRandomFilter () {
b.keys()
for (let i = 0; i < amount; i++) {
b.set({
[i % 2 ? i + 'e' : i]: {
[i % 5 ? i + 'e' : i]: {
order: ~~(Math.random() * amount)
}
})
Expand All @@ -122,9 +122,7 @@ function orderedManyEscaped () {
e_bla: { order: 2e3 },
define: {
filter (key) {
if (this[key]) {
return /e/.test(key)
}
return /e/.test(key)
}
},
'1e': { order: 20 },
Expand All @@ -142,6 +140,6 @@ function orderedManyEscaped () {
}
}

test(orderedKeysRandom, setKeysRandom, 2)
test(orderedKeysRandomFilter, orderedKeysRandom, 1)
test(orderedManyEscaped, orderedKeysRandomFilter, 1)
test(orderedKeysRandom, setKeysRandom, 2.5)
test(orderedKeysRandomFilter, orderedKeysRandom, 1.5)
test(orderedManyEscaped, orderedKeysRandomFilter, 1.25)

0 comments on commit 266e0d8

Please sign in to comment.