2020-08-21 16:38:21 +00:00
|
|
|
import { EventLayer } from "../lib/communication/eventLayer";
|
2020-08-25 22:11:26 +00:00
|
|
|
import { getLinkedDispatcher } from "../lib/dispatcher/getLinkedDispatcher";
|
|
|
|
import { nopeDispatcher } from "../lib/dispatcher/nopeDispatcher";
|
|
|
|
import { exportFunctionToDispatcher } from "../lib/dispatcher/nopeDispatcherDecorators";
|
|
|
|
import { generateBenchmarkFunction } from "../modules/funcs/generateBenchmarkFunction";
|
2020-08-21 16:38:21 +00:00
|
|
|
|
|
|
|
const communicationLayer = new EventLayer();
|
2020-08-23 07:28:03 +00:00
|
|
|
const local = new nopeDispatcher(communicationLayer);
|
2020-08-21 16:38:21 +00:00
|
|
|
|
2020-08-25 22:11:26 +00:00
|
|
|
const _functionRemote = exportFunctionToDispatcher(async (a: number, b: number, operation: (a: number, b: number) => number) => {
|
2020-08-21 16:38:21 +00:00
|
|
|
return await operation(a, b);
|
2020-08-25 22:11:26 +00:00
|
|
|
}, {
|
|
|
|
uri: '_functionRemote'
|
2020-08-21 16:38:21 +00:00
|
|
|
});
|
|
|
|
|
2020-08-25 22:11:26 +00:00
|
|
|
const remote = getLinkedDispatcher(communicationLayer);
|
|
|
|
|
2020-08-21 16:38:21 +00:00
|
|
|
const main = async () => {
|
|
|
|
let res = await local.performCall<number>('_functionRemote', [1, 2, async (a, b) => {
|
|
|
|
console.log('local callback')
|
|
|
|
return a + b;
|
|
|
|
}]);
|
|
|
|
|
|
|
|
console.log('1', res)
|
|
|
|
|
|
|
|
res = await local.performCall<number>('_functionRemote', [1, 2, async (a, b) => {
|
|
|
|
console.log('local callback')
|
|
|
|
return a * b;
|
|
|
|
}]);
|
|
|
|
|
2020-08-25 22:11:26 +00:00
|
|
|
let max = 100000;
|
|
|
|
let i = 0;
|
|
|
|
|
|
|
|
const benchmark = generateBenchmarkFunction(max, '');
|
|
|
|
|
|
|
|
while (i < max * 10) {
|
|
|
|
await local.performCall<number>('_functionRemote', [1, 2, async (a, b) => {
|
|
|
|
return 1
|
|
|
|
}], {
|
|
|
|
deletableCallbacks: [2]
|
|
|
|
});
|
|
|
|
|
|
|
|
benchmark();
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
2020-08-21 16:38:21 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
main();
|
|
|
|
|