Console.log (v28)

Revision 28 of this benchmark created on


Setup

class Logger {
    constructor(batchSize = 500, interval = 1000) {
        this.cache = [];
        this.batchSize = batchSize;
        this.interval = interval;

        this.startConsuming();
    }

    log(message) {
        this.cache.push({
            timestamp: new Date().toISOString(),
            message: message
        });
        if (this.cache.length >= this.batchSize) {
            this.consumeCache();
        }
    }

    startConsuming() {
        setInterval(() => {
            if (this.cache.length > 0) {
                this.consumeCache();
            }
        }, this.interval);
    }

    consumeCache() {
        const batch = this.cache.splice(0, this.batchSize);

        this.processBatch(batch);
    }

    processBatch(batch) {

        console.log(`Processing batch of ${batch.length} records`);
        // simulating write logs into rust-sdk
        let logs_ = JSON.stringify(batch); 
        console.log(logs_);
    }
}

// Usage example
const logger = new Logger(500, 1000);

const customLog = function(log) {
	logger.log(log)
}

Test runner

Ready to run.

Testing in
TestOps/sec
customLogger
customLog('Logging stuff');
ready
Console.log
console.log('Logging stuff');
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.