Skip to content

Commit 63787bb

Browse files
committed
perf: more copyFile benchmarks
1 parent 8c9ef3e commit 63787bb

File tree

2 files changed

+63
-2
lines changed

2 files changed

+63
-2
lines changed

test/benchmarks/content.read.js

+27-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,33 @@ module.exports = (suite, CACHE) => {
6262
}
6363
})
6464

65-
suite.add('content.read.copy()', {
65+
suite.add('content.read.copy() small data', {
66+
defer: true,
67+
setup () {
68+
const fixture = new Tacks(CacheContent({
69+
[INTEGRITY]: CONTENT
70+
}))
71+
fixture.create(CACHE)
72+
},
73+
fn (deferred) {
74+
if (read.copy) {
75+
read.copy(CACHE, INTEGRITY, path.join(CACHE, 'data'))
76+
.then(
77+
() => deferred.resolve(),
78+
err => deferred.reject(err)
79+
)
80+
} else {
81+
read(CACHE, INTEGRITY)
82+
.then(data => fs.writeFileAsync(path.join(CACHE, 'data'), data))
83+
.then(
84+
() => deferred.resolve(),
85+
err => deferred.reject(err)
86+
)
87+
}
88+
}
89+
})
90+
91+
suite.add('content.read.copy() big data', {
6692
defer: true,
6793
setup () {
6894
const fixture = new Tacks(CacheContent({

test/benchmarks/get.js

+36-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const CacheContent = require('../util/cache-content')
44
const memo = require('../../lib/memoization')
5+
const path = require('path')
56
const Tacks = require('tacks')
67
const ssri = require('ssri')
78

@@ -77,7 +78,7 @@ module.exports = (suite, CACHE) => {
7778
}
7879
})
7980

80-
suite.add('get.stream() big data', {
81+
suite.add('get.stream.byDigest() big data', {
8182
defer: true,
8283
setup () {
8384
const fixture = new Tacks(CacheContent({
@@ -94,4 +95,38 @@ module.exports = (suite, CACHE) => {
9495
})
9596
}
9697
})
98+
99+
suite.add('get.copy.byDigest() small data', {
100+
defer: true,
101+
setup () {
102+
const fixture = new Tacks(CacheContent({
103+
[INTEGRITY]: CONTENT
104+
}))
105+
fixture.create(CACHE)
106+
},
107+
fn (deferred) {
108+
get.copy.byDigest(CACHE, INTEGRITY, path.join(CACHE, 'data'))
109+
.then(
110+
() => deferred.resolve(),
111+
err => deferred.reject(err)
112+
)
113+
}
114+
})
115+
116+
suite.add('get.copy.byDigest() big data', {
117+
defer: true,
118+
setup () {
119+
const fixture = new Tacks(CacheContent({
120+
[BIGINTEGRITY]: BIGCONTENT
121+
}))
122+
fixture.create(CACHE)
123+
},
124+
fn (deferred) {
125+
get.copy.byDigest(CACHE, BIGINTEGRITY, path.join(CACHE, 'data'))
126+
.then(
127+
() => deferred.resolve(),
128+
err => deferred.reject(err)
129+
)
130+
}
131+
})
97132
}

0 commit comments

Comments
 (0)