Skip to content

Commit

Permalink
Sort results
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Oct 1, 2017
1 parent d4a7977 commit 60dbed3
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const {readFileSync, createWriteStream} = require('fs')
const markdownTables = require('markdown-tables')
const toMD = require('markdown-tables')
const bench = require('./bench')
const path = require('path')
const ora = require('ora')
Expand Down Expand Up @@ -37,26 +37,41 @@ const headers = [
'evict'
];

const buffer = [headers.join(',')]

const keys = Object.keys(lrus)
const size = keys.length
const median = []
const buffer = []

Object.keys(lrus).forEach((lruName, index) =>{
const spinner = ora(`${lruName} ${index}/${size}`).start();

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

let total = 0

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

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 results = sort.map((lru, index) => {
const {name: lruName} = sort[index]
return buffer.find(item => item.includes(lruName))
}).join('\n')

const table = markdownTables(buffer.join('\n'))
console.log(table)
const table = [headers.join(',')].concat(results).join('\n')
console.log(toMD(table))

0 comments on commit 60dbed3

Please sign in to comment.