Skip to content

Commit

Permalink
Add linter and changelog automatization
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Oct 2, 2017
1 parent f5e6dd4 commit 8eadb2d
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 41 deletions.
21 changes: 21 additions & 0 deletions .bumpedrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
files:
- package.json
plugins:
prerelease:
Linting config files:
plugin: bumped-finepack
postrelease:
Generating CHANGELOG file:
plugin: bumped-changelog
Committing new version:
plugin: bumped-terminal
command: 'git add CHANGELOG.md package.json && git commit -m "Release $newVersion"'
Detecting problems before publish:
plugin: bumped-terminal
command: 'git-dirty && npm test'
Publishing tag to GitHub:
plugin: bumped-terminal
command: 'git tag $newVersion && git push && git push --tags'
Publishing to NPM:
plugin: bumped-terminal
command: npm publish
15 changes: 0 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,6 @@ given the strengths and weaknesses of javascript, this is significantly faster t
other implementations, _including_ the C implementation. Likely, the overhead of the C<->js boundry
is partly to blame here.

## Changelog

### 1.0.1
* Jason updated `tiny-lru` and re-ran the tests on a Mac Book Air (13" early 2014 / i7 / 8GB / 512 SSD / macOS 10.12.2) with node.js 7.4.0.

* Jason added `nan` module to avoid a compile error from `lru-native`; it wouldn't compile so results were not changed.

* Jason updated `npm test`.

### 1.0.0
* I implemented a new LRU algorithm [hashlru](https://github.com/dominictarr/hashlru)
that is simpler and faster across the board. It's O(1) like LRU, but does less per operation.

* I removed `tiny-lru` because it was crashing in the get phase.

## License

MIT
22 changes: 11 additions & 11 deletions bench.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict';
'use strict'

const createTimestamp = () => {
const start = Date.now()
Expand All @@ -7,38 +7,38 @@ const createTimestamp = () => {

module.exports = (createLRU, num = 1000) => {
const lru = createLRU(num)

// set
let setTimestamp = createTimestamp()
for(let i = 0; i < num; i++) lru.set(i, Math.random())
for (let i = 0; i < num; i++) lru.set(i, Math.random())
setTimestamp = setTimestamp()

// get
let getTimestamp = createTimestamp()
for(let i = 0; i < num; i++) lru.get(i)
for (let i = 0; i < num; i++) lru.get(i)
getTimestamp = getTimestamp()

// update
let updateTimestmap = createTimestamp()
for(let i = 0; i < num; i++) lru.set(i, Math.random())
for (let i = 0; i < num; i++) lru.set(i, Math.random())
updateTimestmap = updateTimestmap()

// get
let getTimestampTwo = createTimestamp()
for(let i = 0; i < num; i++) lru.get(i)
for (let i = 0; i < num; i++) lru.get(i)
getTimestampTwo = getTimestampTwo()

// evict
let evictTimestamp = createTimestamp()
const evicts = num*2
for(let i = num; i < evicts; i++) lru.set(i, Math.random())
const evicts = num * 2
for (let i = num; i < evicts; i++) lru.set(i, Math.random())
evictTimestamp = evictTimestamp()

return [
setTimestamp,
getTimestamp,
updateTimestmap,
getTimestampTwo,
evictTimestamp
].map(value => Math.round(num / value))
}
}
26 changes: 12 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
'use strict'

const {readFileSync, createWriteStream} = require('fs')
const prettyBytes = require('pretty-bytes')
const toMD = require('markdown-tables')
const bench = require('./bench')
const path = require('path')
const ora = require('ora')
const got = require('got')

const LRU_Cache = require('lru_cache').LRUCache
const LRUCache = require('lru_cache').LRUCache
const Simple = require('simple-lru-cache')
const Fast = require('lru-fast').LRUCache
const QuickLRU = require('quick-lru')
Expand All @@ -26,9 +24,9 @@ const lrus = {
'tiny-lru': require('tiny-lru'),
hashlru: require('hashlru'),
hyperlru: max => hyperlru({max}),
lru_cache: n => new LRU_Cache(n),
lru_cache: n => new LRUCache(n),
lru: require('lru'),
mkc: max => new MKC({max}),
mkc: max => new MKC({max})
}

const N = 200000
Expand All @@ -41,7 +39,7 @@ const headers = [
'update',
'get2',
'evict'
];
]

const cases = Object.keys(lrus)
const totalCases = cases.length
Expand All @@ -58,28 +56,28 @@ let index = 0

;(async () => {
for (const lruName of cases) {
const spinner = ora(`${lruName} ${++index}/${totalCases}`).start();
const spinner = ora(`${lruName} ${++index}/${totalCases}`).start()
const [size, gzip] = await fetchSize(lruName)

const lru = lrus[lruName]
const result = bench(lru, N)
let total = 0

const output = result.reduce((acc, value, index) => {
total += value
acc.push(value)
return acc
}, [`[${lruName}](https://npm.im/${lruName})`, size, gzip])

median.push({name: lruName, total})
buffer.push(output.join(','))
spinner.stop()
}

const sort = median.sort(function compare(b, a) {
if (a.total < b.total) return -1;
if (a.total > b.total) return 1;
return 0;
const sort = median.sort(function compare (b, a) {
if (a.total < b.total) return -1
if (a.total > b.total) return 1
return 0
})

const results = sort.map((lru, index) => {
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,15 @@
"quick-lru": "~1.1.0",
"secondary-cache": "^1.2.1",
"simple-lru-cache": "0.0.2",
"standard": "~10.0.3",
"standard-markdown": "~4.0.2",
"tiny-lru": "^1.4.1",
"tiny-lru-cache": "^1.0.1"
},
"scripts": {
"test": "node index.js"
"lint": "standard-markdown && standard",
"pretest": "npm run lint",
"test": "echo 'no tests yet'"
},
"license": "MIT"
}

0 comments on commit 8eadb2d

Please sign in to comment.