Skip to main content

Cpp.js

Bind C++ to JavaScript with no extra code

Google Chrome
Mozilla Firefox
Apple Safari
React Native
Android (React Native)
iOS (React Native)
Node.js
Cloudflare Workers
/src/index.js
import { initCppJs } './native/Matrix.h';

const { Matrix } = await initCppJs();
const a = new Matrix(1210000, 1);
const b = new Matrix(1210000, 2);
const result = a.multiple(b);
console.log(result.get(0)); // execution time: 0.872s
/src/native/Matrix.h
class Matrix : public std::vector<int> {
public:
Matrix(int size, int v) : std::vector<int>(size, v) {}
int get(int i) { return this->at(i); }
std::shared_ptr<Matrix> multiple(std::shared_ptr<Matrix> b) {
int size = sqrt(this->size());
auto result = std::make_shared<Matrix>(this->size(), 0);

for (int i = 0; i < size; i += 1) {
for (int j = 0; j < size; j += 1) {
for (int k = 0; k < size; k += 1) {
(*result)[i*size+j]+=this->at(i*size+k)*(*b)[k*size+j];
}
}
}
return result;
}
};

High Performance Execution

Cpp.js is engineered to provide high execution speeds, optimizing performance for applications. By compiling C++ code into WebAssembly for the web and native machine code for mobile, it ensures maximum efficiency and performance.

Cpp.js

0.872s

JavaScript

6.75x
5.886s

Prebuilt Libraries

Cpp.js offers a range of precompiled libraries, enabling effortless integration into your projects without the need for manual compilation. These libraries streamline the development process, allowing you to focus on building high-performance applications.

Additionally, users can create and distribute their own precompiled libraries, further enhancing flexibility and collaboration within the developer community.

Multi-Platform

Develop applications for Web, Mobile, and Backend using a single codebase with C++ and JavaScript.

Supports Google Chrome, Mozilla Firefox, Apple Safari, React Native, Android, iOS, Node.js, and Cloudflare Workers.

Google Chrome
Mozilla Firefox
Apple Safari
React Native
Android (React Native)
iOS (React Native)
Node.js
Cloudflare Workers

Seamless Integration

Seamless integration with plugins designed for a wide range of bundlers.

Supports Webpack, Rollup, Vite, Rspack, Create React App (CRA), React Native, Metro, Gradle, Cocoapods.

Webpack
Rollup
Vite
Rspack
React Native
Metro
Gradle
Cocoapods

Widespread Adoption of WebAssembly

Many companies are rapidly adopting WebAssembly to enhance performance and expand their web capabilities. Some notable examples of successful implementations include: