-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tim Voronov
committed
Nov 19, 2016
1 parent
c97126d
commit 149ab62
Showing
9 changed files
with
170 additions
and
24 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import times from './utils/times'; | ||
import format from './utils/format-memory'; | ||
import report from './utils/reporter'; | ||
import Container from '../../src/index'; | ||
|
||
const cycles = 20; | ||
const objects = 50000; | ||
const container = new Container(); | ||
const initialMemory = process.memoryUsage().heapUsed; | ||
|
||
report('Memory. With dependencies'); | ||
report(`Initial memory usage ${format(initialMemory)}`, 1, '-'); | ||
|
||
times(cycles, (cycle) => { | ||
times(objects, (idx) => { | ||
container.namespace(`${idx}_namespace`).value(`${idx}_value`, {}); | ||
container.factory(`${idx}_factory`, [ | ||
`${idx}_namespace/${idx}_value` | ||
], (dep) => { | ||
return [dep]; | ||
}); | ||
|
||
container.resolve(`${idx}_factory`); | ||
}); | ||
|
||
report.update(`Allocated ${objects} objects in ${cycle} cycle`, 2); | ||
container.clear(); | ||
global.gc(); | ||
}); | ||
|
||
report('Finished. Pause'); | ||
setTimeout(() => { | ||
const releasedMemory = process.memoryUsage().heapUsed; | ||
|
||
report(`Final released memory usage ${format(releasedMemory)}`, 1); | ||
report(`Initial: ${format(initialMemory)}, final: ${format(releasedMemory)}`, 1); | ||
}, 1000); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import times from './utils/times'; | ||
import format from './utils/format-memory'; | ||
import report from './utils/reporter'; | ||
import Container from '../../src/index'; | ||
|
||
const cycles = 20; | ||
const objects = 50000; | ||
const container = new Container(); | ||
const initialMemory = process.memoryUsage().heapUsed; | ||
|
||
report('Memory. With namespaces'); | ||
report(`Initial memory usage ${format(initialMemory)}`, 1, '-'); | ||
|
||
times(cycles, (cycle) => { | ||
times(objects, (idx) => { | ||
container.namespace(`${idx}_namespace`).value(`${idx}_value`, {}); | ||
container.resolve(`${idx}_namespace/${idx}_value`); | ||
}); | ||
|
||
report.update(`Allocated ${objects} objects in ${cycle} cycle`, 2); | ||
container.clear(); | ||
global.gc(); | ||
}); | ||
|
||
report('Finished. Pause'); | ||
setTimeout(() => { | ||
const releasedMemory = process.memoryUsage().heapUsed; | ||
|
||
report(`Final released memory usage ${format(releasedMemory)}`, 1); | ||
report(`Initial: ${format(initialMemory)}, final: ${format(releasedMemory)}`, 1); | ||
}, 1000); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import times from './utils/times'; | ||
import format from './utils/format-memory'; | ||
import report from './utils/reporter'; | ||
import Container from '../../src/index'; | ||
|
||
const cycles = 20; | ||
const objects = 50000; | ||
const container = new Container(); | ||
const initialMemory = process.memoryUsage().heapUsed; | ||
|
||
report('Memory. Without namespaces'); | ||
report(`Initial memory usage ${format(initialMemory)}`, 1, '-'); | ||
|
||
times(cycles, (cycle) => { | ||
times(objects, (idx) => { | ||
container.value(`${idx}_${cycle}_value`, {}); | ||
container.resolve(`${idx}_${cycle}_value`); | ||
}); | ||
|
||
report.update(`Allocated ${objects} objects in ${cycle} cycle`, 2); | ||
container.clear(); | ||
global.gc(); | ||
}); | ||
|
||
report('Finished. Pause'); | ||
setTimeout(() => { | ||
const releasedMemory = process.memoryUsage().heapUsed; | ||
|
||
report(`Final released memory usage ${format(releasedMemory)}`, 1); | ||
report(`Initial: ${format(initialMemory)}, final: ${format(releasedMemory)}`, 1); | ||
}, 1000); |
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import times from './times'; | ||
|
||
function format(message, tabs = 0, tabChar = ' ') { | ||
const output = []; | ||
|
||
times(tabs, () => { | ||
output.push(`${tabChar}${tabChar}`); | ||
}); | ||
|
||
output.push(message); | ||
|
||
return output.join(' '); | ||
} | ||
|
||
function report(message, tabs = 0, tabChar = ' ') { | ||
console.log(format(message, tabs, tabChar)); | ||
} | ||
|
||
report.update = (message, tabs, tabChar) => { | ||
console.log(format(message, tabs, tabChar)); | ||
}; | ||
|
||
export default report; |
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,10 @@ | ||
require('babel-register'); | ||
require('./memory'); | ||
import memory from './memory'; | ||
|
||
memory((err) => { | ||
if (err) { | ||
console.error(err); | ||
return; | ||
} | ||
|
||
console.log('Done'); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,41 @@ | ||
import times from './utils/times'; | ||
import format from './utils/format-memory'; | ||
import Container from '../src/index'; | ||
import glob from 'glob'; | ||
import path from 'path'; | ||
import { spawn } from 'child_process'; | ||
|
||
const cycles = 100; | ||
const objects = 100000; | ||
const container = new Container(); | ||
const initialMemory = process.memoryUsage().heapUsed; | ||
export default function run(done) { | ||
glob(path.join(__dirname, 'benchs/memory-*'), (err, files) => { | ||
if (err) { | ||
return done(err); | ||
} | ||
|
||
console.log('Initial memory usage', format(initialMemory)); | ||
console.log('Allocating', objects, 'objects in', cycles, 'cycles'); | ||
console.log('Found files', files.length); | ||
|
||
times(cycles, () => { | ||
times(objects, (idx) => { | ||
container.const(idx.toString(), idx); | ||
}); | ||
const next = () => { | ||
if (!files.length) { | ||
return done(); | ||
} | ||
|
||
const file = files.shift(); | ||
const proc = spawn('node', [ | ||
'--expose-gc', | ||
'-e', | ||
`require("babel-register"); require("${file}");` | ||
]); | ||
|
||
proc.on('error', done); | ||
proc.on('exit', next); | ||
|
||
container.clear(); | ||
global.gc(); | ||
}); | ||
proc.stderr.on('data', (data) => { | ||
done(data.toString()); | ||
}); | ||
|
||
console.log('Finished. Pause'); | ||
setTimeout(() => { | ||
const releasedMemory = process.memoryUsage().heapUsed; | ||
proc.stdout.on('data', (data) => { | ||
console.log(data.toString()); | ||
}); | ||
|
||
console.log('Final released memory usage', format(releasedMemory)); | ||
}, 1000); | ||
return null; | ||
}; | ||
|
||
return next(); | ||
}); | ||
} |
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