123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- const Eventual = require('./lib/eventual.js');
- const Benchmark = require('../../lib/utils/benchmark');
- function makeid()
- {
- var text = "";
- var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
- for( var i=0; i < 5; i++ )
- text += possible.charAt(Math.floor(Math.random() * possible.length));
- return text;
- }
- var events = new Eventual();
- var cevt= events.createContext();
- var ctx2 = events.createContext();
- function stressEvents() {
- // 1 million
- var ncount = 1000000;
- console.log("Adding",ncount,"events");
- for(var i = 0;i<ncount;i++) {
- // Create random contexts too
- var evtName = makeid() + ":test";
- cevt.on(evtName,(a,b,c,evt) => {
- console.log("evt: " , evt);
- console.log("Args: " + a,b,c);
- });
- }
- // Second context
- console.log("Adding events to second context");
- for(var i = 0;i<ncount;i++) {
- ctx2.on('test:test',(a,b,c) => { });
- };
- }
- stressEvents();
- ctx2.on('c1:ping',() => {
- console.log("Pong from ctx2");
- });
- var pingbm = new Benchmark();
- var pctx = events.createContext();
- pctx .on('c1:ping',() => {
- console.log("Pong: " + pingbm.mark(), "Contexts:",events._events.ctx.length);
- })
- var test = 0;
- setInterval(() => {
- pingbm.start();
- console.log("Sending ping");
- pctx.broadcast('c1:ping');
- if( test > 5) {
- cevt.destroy();
- ctx2.destroy();
- }
- test++;
- },1000);
|