CPU performance benchmarking library for React Native with MD5 brute-force implementations in JavaScript, Rust, and Kotlin.
rn-compute-bench is a React Native library that enables developers to benchmark CPU-intensive operations across three different execution environments:
- JavaScript (React Native) - Pure JS implementation running in the JS engine
- Rust (TurboModules + FFI) - Native high-performance implementation via TurboModules and Rust FFI
- Kotlin (Native Android) - Native Android implementation with coroutines
Perfect for profiling device performance, comparing native vs JS execution, and testing CPU-bound workloads in production apps.
- Type-Safe API - Full TypeScript support with detailed types
- Production Ready - Optimized implementations with cancellation support
- Example App Included - Full-featured benchmark UI
npm install rn-compute-bench
# or
yarn add rn-compute-bench- React Native 0.76+ with New Architecture enabled
- Android: API Level 21+
- iOS: iOS 13+
import {
MD5BruteForceRust,
MD5BruteForceKotlin,
MD5BruteForceJS,
type BruteForceResult,
} from 'rn-compute-bench';
// Using Rust implementation (fastest)
const result = await MD5BruteForceRust.bruteForceHash(
'5d41402abc4b2a76b9719d911017c592', // MD5 hash of "hello"
5 // max length to test
);
console.log(result);
// {
// found: true,
// plaintext: 'hello',
// attempts: 123456,
// timeMs: 45.2,
// checksPerSecond: 2730000
// }
// Using Kotlin implementation (Android only)
const kotlinResult = await MD5BruteForceKotlin.bruteForceHash(
'0cc175b9c0f1b6a831c399e269772661', // MD5 hash of "a"
3
);
// Using JavaScript implementation (cross-platform)
const jsResult = await MD5BruteForceJS.bruteForceHash(
'e4da3b7fbbce2345d7772b0674a318d5', // MD5 hash of "5"
2,
{
onProgress: (attempts, current, checksPerSecond) => {
console.log(`Tested: ${current}, Speed: ${checksPerSecond.toFixed(0)} checks/sec`);
},
shouldCancel: () => userRequestedCancel,
}
);// Rust
const hash = MD5BruteForceRust.generateMd5('hello');
// "5d41402abc4b2a76b9719d911017c592"
// Kotlin (Android only)
const hash = await MD5BruteForceKotlin.generateMd5('hello');
// JavaScript
const hash = MD5BruteForceJS.generateMd5('hello');// Start brute force
const promise = MD5BruteForceRust.bruteForceHash(hash, 10);
// Cancel from another part of your code
MD5BruteForceRust.cancelBruteForce();
// JavaScript cancellation via callback
let shouldStop = false;
const jsPromise = MD5BruteForceJS.bruteForceHash(hash, 10, {
shouldCancel: () => shouldStop,
});
// Later...
shouldStop = true;High-performance Rust implementation
-
bruteForceHash(targetHash: string, maxLength: number): Promise<BruteForceResult>Attempts to crack an MD5 hash by testing combinations up to
maxLengthcharacters. -
cancelBruteForce(): voidCancels the ongoing brute force operation.
-
generateMd5(input: string): stringGenerates an MD5 hash from the input string.
Native Kotlin implementation with coroutines.
Same as MD5BruteForceRust but:
generateMd5(input: string): Promise<string>- Returns a promise
Note: Only available on Android.
Pure JavaScript implementation with progress callbacks.
-
bruteForceHash(targetHash: string, maxLength: number, callbacks?: BruteForceCallbacks): Promise<BruteForceResult>JavaScript implementation with optional progress tracking.
interface BruteForceCallbacks { onProgress?: (attempts: number, current: string, checksPerSecond: number) => void; shouldCancel?: () => boolean; }
-
generateMd5(input: string): string
interface BruteForceResult {
found: boolean;
plaintext: string;
attempts: number;
timeMs: number;
checksPerSecond: number;
}Character Set: 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ (62 characters)
Performance Comparison (cracking "deal" hash - 4 characters, 3,394,956 attempts):
- JavaScript: 131.84s @ 25,751 checks/sec
- Kotlin: 4.88s @ 695,973 checks/sec (27x faster)
- Rust: 2.09s @ 1,626,009 checks/sec (63x faster)
Don't want to build from source? Download and install the pre-built benchmark app:
Requirements: Android 6.0 (API 23) or higher
See the releases folder for more details.
Alternatively, build and run the example app yourself:
# Clone the repository
git clone https://github.com/iNerdstack/rn-compute-bench.git
cd rn-compute-bench
# Install dependencies
yarn install
cd example && yarn install && cd ..
# Run on Android
cd example && yarn androidThe example app includes:
- Interactive hash input with presets
- Mode selector (JS/Rust/Kotlin)
- Real-time performance metrics
- Visual results comparison
- Example test hashes
- Device Profiling: Measure CPU performance across different device models
- Performance Testing: Benchmark native vs JavaScript performance
- Load Testing: Test app behavior under CPU-intensive operations
- Cross-Platform Comparison: Compare iOS (Rust) vs Android (Rust/Kotlin) performance
- Educational: Learn about native module integration and performance optimization
If you want to modify the native implementations:
# Prerequisites
# - Rust 1.82+ (https://rustup.rs/)
# - Android NDK (set ANDROID_NDK_HOME)
# Install dependencies
yarn install
# Generate TurboModule bindings (using Craby)
npx crabygen
# Build native modules
npx crabygen build
# Test changes
cd example && yarn androidrn-compute-bench/
├── src/ # TypeScript module exports
│ ├── index.ts # Main exports
│ ├── NativeBruteForceRust.ts # Rust module spec
│ ├── BruteForceKotlin.ts # Kotlin module interface
│ └── MD5BruteForceJS.ts # JS implementation
├── crates/ # Rust implementation
│ └── lib/src/
│ └── brute_force_rust_impl.rs
├── android/ # Android native module
│ └── src/main/java/com/rncomputebench/
│ └── NativeBruteForceKotlinModule.kt
├── cpp/ # C++ bridging (auto-generated)
└── example/ # Example React Native app
└── src/
└── screens/BenchmarkScreen.tsx
Contributions are welcome! Ideas for improvements:
- Implement parallel processing optimizations
- Add performance visualization graphs
- Create benchmarking presets for common operations
MIT License - See LICENSE file for details.
Nerd Stack
- Email: isaacajetunmobi@gmail.com
- GitHub: @iNerdstack
Note: This library is designed for performance testing and educational purposes.



