GithubHelp home page GithubHelp logo

steren / javascript-vs-native-addon-prime-numbers Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fhinkel/javascript-vs-native-addon-prime-numbers

0.0 2.0 0.0 199 KB

Speed up your Node.js App with Native Addons. What’s faster, C++ or JavaScript?

Home Page: https://medium.com/@fhinkel/speed-up-your-node-js-app-with-native-addons-5e76a06f4a40

License: MIT License

Python 10.91% JavaScript 57.04% C++ 32.04%

javascript-vs-native-addon-prime-numbers's Introduction

Speed up your Node.js App with Native Addons. What’s faster, C++ or JavaScript?

This example compares JavaScript to C++ in Node.js for computing prime numbers.

JavaScript is a ridiculously fast scripting language thanks to modern JavaScript engines. But how fast is JavaScript compared to C++? This repository contains an example that computes prime numbers in Node both with JavaScript and with a native C++ addon.

Usage

git clone [email protected]:fhinkel/javascript-vs-native-addon-prime-numbers.git
cd javascript-vs-native-addon-prime-numbers
npm install
npm start

Experiment with this example yourself. Just remember to run npm install to recompile the addon if you change any C++ code.

Results

If your Node app’s sole purpose is to compute prime numbers and you don’t want to use a fast lookup table, please rely on this benchmark 100%. For anything else, this benchmark is probably useless.

The JavaScript and the C++ implementation use the same algorithm. Calling into the addon and running the computations in C++ is faster than staying in JavaScript except for small prime numbers, i.e., the first 25 prime numbers.

Computing the first 1,000,000 prime numbers without warm up

Computing the first 1,000,000 prime numbers with Node 9.2.

Computing prime numbers without adaptive optimizations

Computing prime numbers without adaptive optimizations.

License

MIT

javascript-vs-native-addon-prime-numbers's People

Contributors

fhinkel avatar mathiasbynens avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.