Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

benchmarking

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

benchmarking

A benchmarking script that expects promises and number of iterations

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

benchmark-cream

Wrap a promise and send it to loop N times and receive back a time period in seconds. Use the result for benchmarking purposes.

#Motivation

When developing some Node.js module, I wanted to check the speed of different methods. So before writing the code I intended, I decided to publish this script first.

#Example

var Promise = require('bluebird');
var screaper = require('screaper');
var Cream = require('./benchmark-cream');
var options = {selector: "h2", class: "entry-title", endTag: "a", length: "250"};

var giveMeOnePromise = function () {
    return new Promise(function (resolve, reject) {
        screaper.action('http://www.prometod.eu/en/', options).then(function (data) {
            resolve(data)
        }).catch(console.log)
    })
};

Cream.main(100, giveMeOnePromise, function (result) {
    console.log(result)
})

-giveMeOnePromise - a common pattern to wrap your asynchronous function with new promise

-screaper.action - thenable method under benchmarking.

#API

##main(numberLoops, giveMeOnePromise, callback)

-- numberLoops - number iterations -- giveMeOnePromise - thenable -- callback - it returns an object

###.time - time as a number - the period between the start and the finish of benchmarking

###.timeString - time as a string

example output - '38 seconds'

###.data - array of resolved within giveMeOnePromise values

For example, if you resolve a string, you will get array of strings

example output - [resolvedDataStep1,resolvedDataStep2, ... resolvedDataStepN]

##returnTime

same as main but returns only time as number

##each

same as main but uses async's each and returns time as number

##times

same as main but uses async's times and returns an array:

index 0 => time as number

index 1 => array of resolved within giveMeOnePromise values

#Tests

The tests file is not only show the library in actin, but also shows how cool testing is with Unexpected.

Keywords

FAQs

Package last updated on 10 Aug 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc