wasm-bindgen-lite 0.3.2 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/cli/bench.js +34 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wasm-bindgen-lite",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "type": "module",
5
5
  "description": "CLI tool to build Rust crates into minimal, SIMD-optimized WASM packages with JS loaders",
6
6
  "repository": {
package/src/cli/bench.js CHANGED
@@ -191,9 +191,34 @@ function computeStats(times) {
191
191
  }
192
192
 
193
193
  /**
194
- * Generate valid base64 test data
194
+ * Generate test data based on type
195
195
  */
196
- function generateTestData(size, forDecode = false, urlSafe = false) {
196
+ function generateTestData(size, options = {}) {
197
+ const { forDecode = false, urlSafe = false, dataType = 'random' } = options
198
+
199
+ // For compression benchmarks, use compressible data
200
+ if (dataType === 'compressible') {
201
+ // Generate text-like compressible data with repeated patterns
202
+ const patterns = [
203
+ 'The quick brown fox jumps over the lazy dog. ',
204
+ 'Hello, World! This is a test of compressible data. ',
205
+ 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. ',
206
+ '{"key": "value", "number": 12345, "active": true}, ',
207
+ ]
208
+ const data = new Uint8Array(size)
209
+ let pos = 0
210
+ let patternIdx = 0
211
+ while (pos < size) {
212
+ const pattern = patterns[patternIdx % patterns.length]
213
+ const bytes = new TextEncoder().encode(pattern)
214
+ const copyLen = Math.min(bytes.length, size - pos)
215
+ data.set(bytes.slice(0, copyLen), pos)
216
+ pos += copyLen
217
+ patternIdx++
218
+ }
219
+ return data
220
+ }
221
+
197
222
  if (!forDecode) {
198
223
  // For encode: random bytes
199
224
  const data = new Uint8Array(size)
@@ -254,6 +279,9 @@ async function runBenchmarks({ distDir, manifest, exports, benchConfig }) {
254
279
  results[variant.name] = { functions: {} }
255
280
 
256
281
  for (const exp of exports) {
282
+ // Skip exports marked as bench: false
283
+ if (exp.bench === false) continue
284
+
257
285
  const fn = wasm[exp.abi]
258
286
  if (!fn) continue
259
287
 
@@ -266,7 +294,10 @@ async function runBenchmarks({ distDir, manifest, exports, benchConfig }) {
266
294
  // Generate appropriate test data
267
295
  const isDecoder = exp.name.toLowerCase().includes('decode')
268
296
  const isUrlSafe = exp.name.toLowerCase().includes('url')
269
- const testData = generateTestData(size, isDecoder, isUrlSafe)
297
+ // Use compressible data for compression functions
298
+ const isCompressor = exp.name.toLowerCase().includes('compress') && !isDecoder
299
+ const dataType = exp.dataType || (isCompressor ? 'compressible' : 'random')
300
+ const testData = generateTestData(size, { forDecode: isDecoder, urlSafe: isUrlSafe, dataType })
270
301
  const actualInputSize = testData.length
271
302
 
272
303
  // Calculate output size