-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
96 changed files
with
2,007 additions
and
295 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# @wroud/di-tools-benchmark |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{ | ||
"name": "@wroud/di-tools-benchmark", | ||
"type": "module", | ||
"private": true, | ||
"sideEffects": [], | ||
"exports": { | ||
".": "./lib/index.js", | ||
"./*": "./lib/*.js" | ||
}, | ||
"scripts": { | ||
"build:legacy-decorators": "tsc --build tsconfig.legacy-decorators.json", | ||
"build:modern": "tsc --build tsconfig.modern.json", | ||
"build:benchmark": "tsc --build tsconfig.json", | ||
"build": "yarn build:modern && yarn build:legacy-decorators && yarn build:benchmark", | ||
"bench": "benchmark run", | ||
"clear": "rimraf lib" | ||
}, | ||
"files": [ | ||
"package.json", | ||
"LICENSE", | ||
"README.md", | ||
"CHANGELOG.md", | ||
"lib", | ||
"!lib/**/*.d.ts.map", | ||
"!lib/**/*.test.js", | ||
"!lib/**/*.test.d.ts", | ||
"!lib/**/*.test.d.ts.map", | ||
"!lib/**/*.test.js.map", | ||
"!lib/tests", | ||
"!.tsbuildinfo" | ||
], | ||
"packageManager": "yarn@4.5.0", | ||
"devDependencies": { | ||
"@wroud/tsconfig": "workspace:^", | ||
"rimraf": "^6", | ||
"typescript": "^5" | ||
}, | ||
"dependencies": { | ||
"@wroud/di": "workspace:^", | ||
"@wroud/tests-runner": "workspace:^", | ||
"brandi": "^5", | ||
"inversify": "^6", | ||
"reflect-metadata": "^0", | ||
"tslib": "^2", | ||
"tsyringe": "^4", | ||
"vitest": "^2" | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
packages/@wroud/di-tools-benchmark/src/@wroud/createRegisterGet.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { bench } from "vitest"; | ||
import { ServiceContainerBuilder, single } from "@wroud/di"; | ||
import { | ||
createServicesTreeWroudDi, | ||
type ServicePair, | ||
} from "./tests/createServicesTreeWroudDi.js"; | ||
|
||
const singletonServices: ServicePair[] = []; | ||
const rootSingleton = createServicesTreeWroudDi(8, 1, singletonServices)!; | ||
|
||
const transientServices: ServicePair[] = []; | ||
const rootTransient = createServicesTreeWroudDi(8, 1, transientServices)!; | ||
|
||
const scopedServices: ServicePair[] = []; | ||
const rootScoped = createServicesTreeWroudDi(8, 1, scopedServices)!; | ||
|
||
const builder = new ServiceContainerBuilder(); | ||
|
||
for (const { service, impl } of singletonServices) { | ||
builder.addSingleton(service, impl); | ||
} | ||
|
||
for (const { service, impl } of transientServices) { | ||
builder.addTransient(service, impl); | ||
} | ||
|
||
for (const { service, impl } of scopedServices) { | ||
builder.addScoped(service, impl); | ||
} | ||
|
||
const singletonResolver = single(rootSingleton.service); | ||
const transientResolver = single(rootTransient.service); | ||
const scopedResolver = single(rootScoped.service); | ||
|
||
bench( | ||
"[@wroud/di]", | ||
() => { | ||
const serviceProvider = builder.build(); | ||
serviceProvider.getService(singletonResolver); | ||
serviceProvider.getService(transientResolver); | ||
serviceProvider.createScope().serviceProvider.getService(scopedResolver); | ||
}, | ||
{ | ||
time: 5000, | ||
warmupTime: 1000, | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { bench } from "vitest"; | ||
import { ServiceContainerBuilder } from "@wroud/di"; | ||
import { createDeepServices } from "./tests/createDeepServices.js"; | ||
|
||
const { lastService, services } = createDeepServices(10); | ||
|
||
const builder = new ServiceContainerBuilder(); | ||
|
||
for (const { service, impl } of services) { | ||
builder.addTransient(service, impl); | ||
} | ||
|
||
const serviceProvider = builder.build(); | ||
|
||
bench("[@wroud/di]", () => { | ||
serviceProvider.getService(lastService); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { bench } from "vitest"; | ||
import { ServiceContainerBuilder } from "@wroud/di"; | ||
import { createDeepServices } from "./tests/createDeepServices.js"; | ||
|
||
const { lastService, services } = createDeepServices(100); | ||
|
||
const builder = new ServiceContainerBuilder(); | ||
|
||
for (const { service, impl } of services) { | ||
builder.addTransient(service, impl); | ||
} | ||
|
||
const serviceProvider = builder.build(); | ||
|
||
bench("[@wroud/di]", () => { | ||
serviceProvider.getService(lastService); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import { bench } from "vitest"; | ||
import { | ||
createService, | ||
injectable, | ||
ServiceContainerBuilder, | ||
single, | ||
} from "@wroud/di"; | ||
|
||
const a0 = createService("A0"); | ||
const a1 = createService("A1"); | ||
const a2 = createService("A2"); | ||
const a3 = createService("A3"); | ||
const a4 = createService("A4"); | ||
const a5 = createService("A5"); | ||
const a6 = createService("A6"); | ||
const a7 = createService("A7"); | ||
const a8 = createService("A8"); | ||
const a9 = createService("A9"); | ||
@injectable(({ single }) => [ | ||
single(a0), | ||
single(a1), | ||
single(a2), | ||
single(a3), | ||
single(a4), | ||
single(a5), | ||
single(a6), | ||
single(a7), | ||
single(a8), | ||
]) | ||
class A9 { | ||
constructor( | ||
a0: any, | ||
a1: any, | ||
a2: any, | ||
a3: any, | ||
a4: any, | ||
a5: any, | ||
a6: any, | ||
a7: any, | ||
a8: any, | ||
) {} | ||
} | ||
|
||
const builder = new ServiceContainerBuilder() | ||
.addTransient( | ||
a0, | ||
@injectable() | ||
class A0 {}, | ||
) | ||
.addTransient( | ||
a1, | ||
@injectable() | ||
class A1 {}, | ||
) | ||
.addTransient( | ||
a2, | ||
@injectable() | ||
class A2 {}, | ||
) | ||
.addTransient( | ||
a3, | ||
@injectable() | ||
class A3 {}, | ||
) | ||
.addTransient( | ||
a4, | ||
@injectable() | ||
class A4 {}, | ||
) | ||
.addTransient( | ||
a5, | ||
@injectable() | ||
class A5 {}, | ||
) | ||
.addTransient( | ||
a6, | ||
@injectable() | ||
class A6 {}, | ||
) | ||
.addTransient( | ||
a7, | ||
@injectable() | ||
class A7 {}, | ||
) | ||
.addTransient( | ||
a8, | ||
@injectable() | ||
class A8 {}, | ||
) | ||
.addTransient(a9, A9); | ||
|
||
const serviceProvider = builder.build(); | ||
|
||
const a9Resolver = single(a9); | ||
bench("[@wroud/di]", () => { | ||
serviceProvider.getService(a9Resolver); | ||
}); |
23 changes: 23 additions & 0 deletions
23
packages/@wroud/di-tools-benchmark/src/@wroud/get_scoped.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { bench } from "vitest"; | ||
import { | ||
createService, | ||
injectable, | ||
ServiceContainerBuilder, | ||
single, | ||
} from "@wroud/di"; | ||
|
||
const serviceA = createService("serviceA"); | ||
@injectable() | ||
class implA {} | ||
|
||
const scopedProvider = new ServiceContainerBuilder() | ||
.addScoped(serviceA, implA) | ||
.build() | ||
.createScope().serviceProvider; | ||
scopedProvider.getService(serviceA); | ||
|
||
const serviceAResolver = single(serviceA); | ||
|
||
bench("[@wroud/di]", () => { | ||
scopedProvider.getService(serviceAResolver); | ||
}); |
22 changes: 22 additions & 0 deletions
22
packages/@wroud/di-tools-benchmark/src/@wroud/get_singleton.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { bench } from "vitest"; | ||
import { | ||
createService, | ||
injectable, | ||
ServiceContainerBuilder, | ||
single, | ||
} from "@wroud/di"; | ||
|
||
const serviceA = createService("serviceA"); | ||
@injectable() | ||
class implA {} | ||
|
||
const singletonProvider = new ServiceContainerBuilder() | ||
.addSingleton(serviceA, implA) | ||
.build(); | ||
|
||
singletonProvider.getService(serviceA); | ||
|
||
const serviceAResolver = single(serviceA); | ||
bench("[@wroud/di]", () => { | ||
singletonProvider.getService(serviceAResolver); | ||
}); |
20 changes: 20 additions & 0 deletions
20
packages/@wroud/di-tools-benchmark/src/@wroud/get_transient.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { bench } from "vitest"; | ||
import { | ||
createService, | ||
injectable, | ||
ServiceContainerBuilder, | ||
single, | ||
} from "@wroud/di"; | ||
|
||
const serviceA = createService("serviceA"); | ||
@injectable() | ||
class implA {} | ||
|
||
const serviceProvider = new ServiceContainerBuilder() | ||
.addTransient(serviceA, implA) | ||
.build(); | ||
|
||
const serviceAResolver = single(serviceA); | ||
bench("[@wroud/di]", () => { | ||
serviceProvider.getService(serviceAResolver); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { bench } from "vitest"; | ||
import { createService, injectable, ServiceContainerBuilder } from "@wroud/di"; | ||
|
||
const service = createService("service"); | ||
@injectable() | ||
class impl {} | ||
|
||
bench("[@wroud/di] singleton", () => { | ||
const builder = new ServiceContainerBuilder(); | ||
builder.addSingleton(service, impl); | ||
}); | ||
|
||
bench("[@wroud/di] transient", () => { | ||
const builder = new ServiceContainerBuilder(); | ||
builder.addTransient(service, impl); | ||
}); | ||
|
||
bench("[@wroud/di] scoped", () => { | ||
const builder = new ServiceContainerBuilder(); | ||
builder.addScoped(service, impl); | ||
}); |
33 changes: 33 additions & 0 deletions
33
packages/@wroud/di-tools-benchmark/src/@wroud/register_1000.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { bench } from "vitest"; | ||
import { createService, injectable, ServiceContainerBuilder } from "@wroud/di"; | ||
|
||
const services: { service: any; impl: any }[] = []; | ||
|
||
for (let i = 0; i < 1000; i++) { | ||
@injectable() | ||
class impl {} | ||
const service = createService("service"); | ||
|
||
services.push({ service, impl }); | ||
} | ||
|
||
bench("[@wroud/di] singleton", () => { | ||
const builder = new ServiceContainerBuilder(); | ||
for (const { service, impl } of services) { | ||
builder.addSingleton(service, impl); | ||
} | ||
}); | ||
|
||
bench("[@wroud/di] transient", () => { | ||
const builder = new ServiceContainerBuilder(); | ||
for (const { service, impl } of services) { | ||
builder.addTransient(service, impl); | ||
} | ||
}); | ||
|
||
bench("[@wroud/di] scoped", () => { | ||
const builder = new ServiceContainerBuilder(); | ||
for (const { service, impl } of services) { | ||
builder.addScoped(service, impl); | ||
} | ||
}); |
Oops, something went wrong.