MCPcopy Create free account
hub / github.com/apache/fory / start

Function start

javascript/benchmark/platform-buffer.js:30–98  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

28});
29
30async function start() {
31 const result = {
32 writeComparison: {},
33 toStringComparison: {},
34 }
35
36 {
37 const platformBufferA = new BrowserBuffer(jsonString.length);
38 const platformBufferB = new BrowserBuffer(jsonString.length);
39 const nativeBuffer = Buffer.alloc(jsonString.length);
40
41 var suite = new Benchmark.Suite();
42 suite
43 .add("browser utf8Write", function () {
44 platformBufferA.utf8Write(jsonString, 0);
45 })
46 .add("browser write", function () {
47 platformBufferB.write(jsonString, 0, 'utf8');
48 })
49 .add("native write", function () {
50 nativeBuffer.write(jsonString, 0, 'utf8');
51 })
52 .on("complete", function (e) {
53 e.currentTarget.forEach(({ name, hz }) => {
54 result.writeComparison[name] = Math.ceil(hz);
55 });
56 })
57 .run({ async: false });
58 console.log("Write operation per second")
59 console.table(result.writeComparison);
60 }
61
62 {
63 const browserBuffer = new BrowserBuffer(jsonString.length);
64 const nativeBuffer = Buffer.alloc(jsonString.length);
65 browserBuffer.write(jsonString, 0, 'utf8');
66 nativeBuffer.write(jsonString, 0, 'utf8');
67
68 var suite = new Benchmark.Suite();
69 suite
70 .add("browser toString", function () {
71 browserBuffer.toString('utf8', 0, jsonString.length);
72 })
73 .add("native toString", function () {
74 nativeBuffer.toString('utf8', 0, jsonString.length);
75 })
76 .on("complete", function (e) {
77 e.currentTarget.forEach(({ name, hz }) => {
78 result.toStringComparison[name] = Math.ceil(hz);
79 });
80 })
81 .run({ async: false });
82 console.log("toString operation per second")
83 console.table(result.toStringComparison);
84 }
85
86 const args = ['platform-buffer-draw.py', result.writeComparison['browser utf8Write'], result.writeComparison['browser write'], result.writeComparison['native write'], result.toStringComparison['browser toString'], result.toStringComparison['native toString']];
87

Callers 1

platform-buffer.jsFile · 0.70

Calls 11

utf8WriteMethod · 0.95
writeMethod · 0.95
toStringMethod · 0.95
allocMethod · 0.80
ceilMethod · 0.80
logMethod · 0.80
runMethod · 0.65
addMethod · 0.65
writeMethod · 0.65
toStringMethod · 0.65
forEachMethod · 0.45

Tested by

no test coverage detected