Skip to content

Bun executes code 7 times slower than Node #1421

Description

@denyaalt

Hi,
Continuing the topic "Code doesn't work in Bun [selfDefending=true]" #1404

Unfortunately, the problem is partially solved; the code in bunjs runs 7 times slower than in nodejs.
Below is an example, first we save the code in the obfuscated.js file, then we run it first in nodejs, then in bunjs and compare the results.

const fs=require('fs'), job=require('javascript-obfuscator');
const sourceCode=`function benchmark() {let count = 0;
    for (let i = 2; i < 50000; i++) {let isPrime = true;
        for (let j = 2; j <= Math.sqrt(i); j++) { if (i % j === 0) { isPrime = false; break; } }
        if (isPrime) count++;
    }
}
console.time('ExecutionTime'); benchmark(); console.timeEnd('ExecutionTime');`;

const opt={optionsPreset:'high-obfuscation',target:'node',disableConsoleOutput:false,stringArrayCallsTransformThreshold:1,splitStringsChunkLength:3}
fs.writeFileSync('obfuscated.js', job.obfuscate(sourceCode,opt).getObfuscatedCode());

node obfuscated.js - ExecutionTime: 1.270s
bun obfuscated.js - [7.51s] ExecutionTime

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions