Created
September 2, 2017 07:42
-
-
Save nashibao/a311df98ef15b509152e95fd7acc9264 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
process = require('process') | |
_start = Date.now() | |
_title = "" | |
_mem = 0 | |
tic = (title) -> | |
_title = title | |
_start = Date.now() | |
console.log(_title, '..'); | |
_mem = process.memoryUsage().heapUsed | |
toc = () -> | |
time = (Date.now() - _start) / 1000 | |
console.log('time:', time + ' sec') | |
total = (process.memoryUsage().heapUsed) / 1000000 | |
up = (process.memoryUsage().heapUsed - _mem) / 1000000 | |
console.log('mem total:', total + ' mb, up:', up); | |
console.log() | |
{crossfilter} = require('./src/crossfilter') | |
data = [] | |
tips = [0,1,2] | |
types = [0..300] | |
tic("create data") | |
i = 0 | |
while i < 5000000 | |
date = (new Date(Date.now() + Math.random() * 1000 * 60 * 60 * 24 * 365)).getTime() | |
total = Math.random() * 300 | |
tip = tips[Math.floor(Math.random() * 3)] | |
type = types[Math.floor(Math.random() * 300)] | |
data.push { | |
date | |
total | |
tip | |
type | |
} | |
i += 1 | |
toc() | |
tic("constructor") | |
cf = crossfilter(data); | |
toc() | |
tic("create dim") | |
allDim = cf.dimension (d) -> 1 | |
dateDim = cf.dimension (d) -> d.date | |
totalDim = cf.dimension (d) -> d.total | |
typeDim = cf.dimension (d) -> d.type | |
tipDim = cf.dimension (d) -> d.tip | |
toc() | |
tic("create group") | |
dateGroup = dateDim.group (date) -> return (new Date(date)).getMonth() | |
dateReduced = dateGroup.reduceSum (d) -> return d.total | |
typeGroup = typeDim.group (type) -> return type | |
typeReduced = typeGroup.reduceSum (d) -> return d.total | |
totalGroup = totalDim.group (total) -> return Math.floor(total / 10) | |
totalReduced = totalGroup.reduceSum (d) -> return d.total | |
countGroup = allDim.group () -> return 1 | |
countReduced = countGroup.reduceCount() | |
sumReduced = countGroup.reduceSum () -> return 1 | |
toc() | |
tic("filter") | |
totalDim.filter([100, 200]) | |
typeDim.filter('tab') | |
tipDim.filter(0) | |
toc() | |
tic("all count") | |
countReduced.top(1) | |
toc() | |
tic("all sum") | |
sumReduced.top(1) | |
toc() | |
tic("top3 by group") | |
typeReduced.top(3) | |
totalReduced.top(3) | |
dateReduced.top(3) | |
toc() | |
tic("update filter") | |
totalDim.filter([200, 300]) | |
toc() | |
tic("top3 by group") | |
typeReduced.top(3) | |
totalReduced.top(3) | |
dateReduced.top(3) | |
toc() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
構造上distributed/treeにすることも可能。処理が group x filter x reduce であればやはりこれはありな気がする。