Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POC: tryEnd #98

Closed
wants to merge 1 commit into from
Closed

POC: tryEnd #98

wants to merge 1 commit into from

Conversation

cesco69
Copy link
Contributor

@cesco69 cesco69 commented Feb 26, 2025

from #97

this is a basic benchmark example:

const express = require('../src/index');
const app = express();
app.set("etag", false);
app.set("declarative responses", false);


const strLarge = 'Hello world'.repeat(500_000);


app.get('/with-try-end', (req, res) => {
    res.set('Content-Length', strLarge.length);
    res.end(strLarge)
});
app.get('/without-try-end', (req, res) => {
    // WITHOUT Content-Length DON'T USE tryEnd!
    res.end(strLarge)
});



app.listen(3000, async () => {
    let total = 0;
    for (let index = 0; index < 1000; index++) {
        let start = performance.now();
        await Promise.all([
            fetch('http://localhost:3000/with-try-end').then(res => res.text()),
            fetch('http://localhost:3000/with-try-end').then(res => res.text()),
        ]);
        let end = performance.now() - start;
        total += end;
    }
    console.log('with-try-end', total);
    total = 0;
    for (let index = 0; index < 1000; index++) {
        let start = performance.now();
        await Promise.all([
            fetch('http://localhost:3000/without-try-end').then(res => res.text()),
            fetch('http://localhost:3000/without-try-end').then(res => res.text())
        ]);
        let end = performance.now() - start;
        total += end;
    }
    console.log('without-try-end', total);
});

@cesco69 cesco69 marked this pull request as draft February 26, 2025 16:19
Copy link

pkg-pr-new bot commented Feb 26, 2025

Open in Stackblitz

npm i https://pkg.pr.new/dimdenGD/ultimate-express@98

commit: 1c2c4fc

@cesco69 cesco69 closed this Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant