Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions benchmarks/galtee-invoicing/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
vendor/bundle
.bundle
1 change: 1 addition & 0 deletions benchmarks/galtee-invoicing/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ GEM

PLATFORMS
arm64-darwin-25
x86_64-linux-gnu

DEPENDENCIES
byebug (= 11.1.3)
Expand Down
61 changes: 61 additions & 0 deletions benchmarks/galtee-invoicing/solution/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const proxyquire = require('proxyquire');
const express = require('express');

let stripeListCount = 0;

const stripeMock = (key) => ({
products: {
list: async () => {
stripeListCount++;
// Simulate network delay
await new Promise(resolve => setTimeout(resolve, 50));
return {
data: [
{ id: 'prod_1', metadata: { product_id: 'fr_hike' } },
{ id: 'prod_2', metadata: { product_id: 'gb_hike' } },
{ id: 'prod_3', metadata: { product_id: 'painters_way' } }
]
};
}
}
});

const appMock = express();
// Prevent server from listening
appMock.listen = () => {};

const expressMock = function() { return appMock; };
expressMock.static = () => (req, res, next) => next();
expressMock.json = () => (req, res, next) => next();

const server = proxyquire('./server.js', {
'stripe': stripeMock,
'express': expressMock
});

const getProductsRoute = appMock._router.stack.find(
layer => layer.route && layer.route.path === '/products'
).route.stack[0].handle;

async function runBenchmark() {
console.log("Starting benchmark...");
stripeListCount = 0;

const req = {};
const res = {
json: (data) => data,
status: (code) => ({ json: (data) => data })
};

const start = Date.now();
for (let i = 0; i < 5; i++) {
await getProductsRoute(req, res);
}
const end = Date.now();

console.log(`Total time for 5 requests: ${end - start} ms`);
console.log(`Stripe products.list calls: ${stripeListCount}`);
process.exit(0);
}

runBenchmark();
Loading
Loading