mt-polygon-simplification/benchmarking/src/benchmarkCases/simplifyWasm.js
2019-07-14 20:37:26 +02:00

60 lines
1.4 KiB
JavaScript

import {
loadResult,
loadResultAndFreeMemory,
storeCoords
} from '../../../lib/wasm-util/coordinates.js'
import { simplifyWasm, getModule } from '../../../lib/simplify-wasm/index.js'
import { Case } from './Case.js'
export class simplifyWASMCase extends Case {
get name() {
return 'simplifyWASM'
}
async setup() {
this.parameters.module = await getModule()
}
async fn() {
const { data, tol, highQuality } = this.parameters
await simplifyWasm(data, tol, highQuality)
}
}
export class storeCoordsCase extends Case {
get name() {
return 'storeCoords'
}
async setup() {
this.parameters.module = await getModule()
}
async fn() {
const { module, data } = this.parameters
const buffer = storeCoords(module, data)
module._free(buffer)
}
}
export class loadResultCase extends Case {
get name() {
return 'loadResult'
}
async setup() {
const { data, tol, highQual } = this.parameters
const module = await getModule()
const buffer = storeCoords(module, data)
const result = module._simplify(buffer, data.length * 2, tol, highQual)
module._free(buffer)
this.parameters = { ...this.parameters, module, result }
}
async fn() {
const { module, result } = this.parameters
loadResult(module, result)
}
async tearDown() {
const { module, result } = this.parameters
loadResultAndFreeMemory(module, result)
}
}