https://github.com/mrousavy/nitrobenchmarks
Benchmarks TurboModules vs ExpoModules vs NitroModules
https://github.com/mrousavy/nitrobenchmarks
Last synced: 2 months ago
JSON representation
Benchmarks TurboModules vs ExpoModules vs NitroModules
- Host: GitHub
- URL: https://github.com/mrousavy/nitrobenchmarks
- Owner: mrousavy
- Created: 2024-08-10T11:35:39.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-10-23T07:57:11.000Z (8 months ago)
- Last Synced: 2025-04-10T05:08:54.007Z (2 months ago)
- Language: Swift
- Size: 850 KB
- Stars: 74
- Watchers: 5
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Nitro Benchmarks
A react-native (or actually; Expo) app that compares react-native's **Turbo Modules** vs expo's **Expo Modules** vs @mrousavy's [**Nitro Modules**](https://github.com/mrousavy/react-native-nitro).
## About
This app specifically benchmarks the time it takes to call a synchronous function and return a result back to JS.
There are two synchronous functions per module:
- `addNumbers(a: number, b: number): number`
- `addStrings(a: string, b: string): string`For each module, I chose the recommended language for iOS - so the TurboModule is implemented in **Objective-C**, and both the Expo Module and Nitro Module are implemented in **Swift**.
The functions are run 100.000 times after a short timeout to make sure the JS VM isn't busy with any other scheduled microtasks, and the total execution time is measured with `performance.now()`.
### About Nitro
Nitro is an upcoming library/toolkit I have been working on because I hit a lot of limitations with my libraries ([react-native-vision-camera](https://github.com/mrousavy/react-native-vision-camera), [react-native-mmkv](https://github.com/mrousavy/react-native-mmkv), [react-native-filament](https://github.com/margelo/react-native-filament), and so on).
I will use Nitro in my libraries to allow me to make them much faster than they already are, and to benefit from some fundamental differences such as it's instance-based approach. The `Frame` in VisionCamera, or `MMKV` in MMKV, or anything in Filament are all a C++ objects - I needed a better way of exposing those to JS, so I built Nitro.I will make Nitro publicly available for everyone to build native C++, Swift or Kotlin modules with! 🔥
## Results
### iPhone 15 Pro (Release)
On my iPhone 15 Pro I got these numbers in a release build:
ExpoModules
TurboModules
NitroModules
100.000xaddNumbers(...)
434.85
115.86ms
7.27ms
100.000xaddStrings(...)
429.53ms
179.02ms
29.94ms
- For `addNumbers(...)`, Nitro Modules is **59x as fast as ExpoModules**, and **15x as fast as TurboModules** 🔥
- For `addStrings(...)`, Nitro Modules is **13x as fast as ExpoModules**, and **5x as fast as TurboModules** 🔥---
### Mac Studio (Apple M1 Max)
On my Mac Studio (Apple M1 Max, 32GB RAM), I got these numbers in a release build ("designed for iPad"):
ExpoModules
TurboModules
NitroModules
100.000xaddNumbers(...)
764.31ms
195.12ms
42.32ms
100.000xaddStrings(...)
773.00ms
308.65ms
138.43ms
## Real-world
Note that these are just very specific benchmarks. They profile JS <-> Native function execution time (call, argument parsing, and result argument conversion).
**In an actual real world app, performance may vary.**## Correctness
Note: I put these benchmarks together in ~1 hour. My focus is on making [Nitro Modules](https://github.com/mrousavy/react-native-nitro) as fast as possible, but also as powerful as possible, so this is where my time is dedicated at.
**If I made any mistakes in the benchmark, please let me know so I can update it asap!**I don't intend to put Turbo or Expo modules in bad light here, they are insanely cool tools to build native modules.