Skip to content

Commit 4c51172

Browse files
add other react-native-get-random-values implementations for benchmarks
1 parent e0bcfcf commit 4c51172

File tree

5 files changed

+62
-7
lines changed

5 files changed

+62
-7
lines changed

example/index.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
declare module "react-native-get-random-values" {
2+
export function getRandomValues<T extends Uint8Array | Uint16Array | Uint32Array>(array: T): T;
3+
}

example/ios/Podfile.lock

+9-3
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,8 @@ PODS:
956956
- React-Mapbuffer (0.74.2):
957957
- glog
958958
- React-debug
959+
- react-native-get-random-values (1.11.0):
960+
- React-Core
959961
- React-nativeconfig (0.74.2)
960962
- React-NativeModulesApple (0.74.2):
961963
- glog
@@ -1185,7 +1187,7 @@ PODS:
11851187
- React-logger (= 0.74.2)
11861188
- React-perflogger (= 0.74.2)
11871189
- React-utils (= 0.74.2)
1188-
- RNSodium (0.1.1):
1190+
- RNSodium (0.2.0):
11891191
- DoubleConversion
11901192
- glog
11911193
- hermes-engine
@@ -1244,6 +1246,7 @@ DEPENDENCIES:
12441246
- React-jsitracing (from `../node_modules/react-native/ReactCommon/hermes/executor/`)
12451247
- React-logger (from `../node_modules/react-native/ReactCommon/logger`)
12461248
- React-Mapbuffer (from `../node_modules/react-native/ReactCommon`)
1249+
- react-native-get-random-values (from `../node_modules/react-native-get-random-values`)
12471250
- React-nativeconfig (from `../node_modules/react-native/ReactCommon`)
12481251
- React-NativeModulesApple (from `../node_modules/react-native/ReactCommon/react/nativemodule/core/platform/ios`)
12491252
- React-perflogger (from `../node_modules/react-native/ReactCommon/reactperflogger`)
@@ -1338,6 +1341,8 @@ EXTERNAL SOURCES:
13381341
:path: "../node_modules/react-native/ReactCommon/logger"
13391342
React-Mapbuffer:
13401343
:path: "../node_modules/react-native/ReactCommon"
1344+
react-native-get-random-values:
1345+
:path: "../node_modules/react-native-get-random-values"
13411346
React-nativeconfig:
13421347
:path: "../node_modules/react-native/ReactCommon"
13431348
React-NativeModulesApple:
@@ -1421,6 +1426,7 @@ SPEC CHECKSUMS:
14211426
React-jsitracing: 0fa7f78d8fdda794667cb2e6f19c874c1cf31d7e
14221427
React-logger: 29fa3e048f5f67fe396bc08af7606426d9bd7b5d
14231428
React-Mapbuffer: bf56147c9775491e53122a94c423ac201417e326
1429+
react-native-get-random-values: 21325b2244dfa6b58878f51f9aa42821e7ba3d06
14241430
React-nativeconfig: 9f223cd321823afdecf59ed00861ab2d69ee0fc1
14251431
React-NativeModulesApple: ff7efaff7098639db5631236cfd91d60abff04c0
14261432
React-perflogger: 32ed45d9cee02cf6639acae34251590dccd30994
@@ -1444,9 +1450,9 @@ SPEC CHECKSUMS:
14441450
React-runtimescheduler: 56b642bf605ba5afa500d35790928fc1d51565ad
14451451
React-utils: 4476b7fcbbd95cfd002f3e778616155241d86e31
14461452
ReactCommon: ecad995f26e0d1e24061f60f4e5d74782f003f12
1447-
RNSodium: 8cf3358f06b37d6778e9cbb4fd38b8439338d685
1453+
RNSodium: 381683159bdd22fc7bc65b6e4e6a8950cbb27bc1
14481454
SocketRocket: abac6f5de4d4d62d24e11868d7a2f427e0ef940d
1449-
Yoga: ae3c32c514802d30f687a04a6a35b348506d411f
1455+
Yoga: 2f71ecf38d934aecb366e686278102a51679c308
14501456

14511457
PODFILE CHECKSUM: 2b476e664f3e7c6b87013748402bfab7c78276e5
14521458

example/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"@react-native/babel-preset": "0.74.84",
2323
"@react-native/metro-config": "0.74.84",
2424
"@react-native/typescript-config": "0.74.84",
25-
"babel-plugin-module-resolver": "^5.0.0"
25+
"babel-plugin-module-resolver": "^5.0.0",
26+
"react-native-get-random-values": "^1.11.0"
2627
},
2728
"engines": {
2829
"node": ">=18"

example/src/App.tsx

+29-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,41 @@
11
import * as React from 'react';
22

33
import { StyleSheet, View, Text } from 'react-native';
4-
import '@korekoi/react-native-get-random-values';
4+
import { getRandomValues } from '@korekoi/react-native-get-random-values';
5+
import { getRandomValues as b64GetRandomValues } from "react-native-get-random-values"
56

67

78
export default function App() {
89
React.useEffect(() => {
9-
const a = new Uint8Array(32);
10+
console.log("====================LIBSODIUM + NITRO=======================")
11+
const loops = 10000
12+
let sum = 0
13+
for (let i = 0; i < loops; i++) {
14+
const start = performance.now()
15+
const a = new Uint32Array(16384)
16+
getRandomValues(a)
1017

11-
console.log("TEST", global.crypto.getRandomValues(a))
18+
const end = performance.now()
19+
sum += end - start
20+
}
21+
console.log(`Average time for ${loops} loops: ${sum / loops}ms`)
1222
}, [])
23+
24+
React.useEffect(() => {
25+
console.log("====================SERIALIZATION WITH SWIFT AND JAVA=======================")
26+
const loops = 1000
27+
let sum = 0
28+
for (let i = 0; i < loops; i++) {
29+
const start = performance.now()
30+
const a = new Uint32Array(16384)
31+
b64GetRandomValues(a)
32+
33+
const end = performance.now()
34+
sum += end - start
35+
}
36+
console.log(`Average time for ${loops} loops: ${sum / loops}ms`)
37+
}, [])
38+
1339
return (
1440
<View style={styles.container}>
1541
<Text>

yarn.lock

+19
Original file line numberDiff line numberDiff line change
@@ -4568,6 +4568,13 @@ __metadata:
45684568
languageName: node
45694569
linkType: hard
45704570

4571+
"fast-base64-decode@npm:^1.0.0":
4572+
version: 1.0.0
4573+
resolution: "fast-base64-decode@npm:1.0.0"
4574+
checksum: 4c59eb1775a7f132333f296c5082476fdcc8f58d023c42ed6d378d2e2da4c328c7a71562f271181a725dd17cdaa8f2805346cc330cdbad3b8e4b9751508bd0a3
4575+
languageName: node
4576+
linkType: hard
4577+
45714578
"fast-deep-equal@npm:^3.1.1, fast-deep-equal@npm:^3.1.3":
45724579
version: 3.1.3
45734580
resolution: "fast-deep-equal@npm:3.1.3"
@@ -7673,10 +7680,22 @@ __metadata:
76737680
babel-plugin-module-resolver: ^5.0.0
76747681
react: 18.2.0
76757682
react-native: 0.74.2
7683+
react-native-get-random-values: ^1.11.0
76767684
react-native-nitro-modules: ^0.9.2
76777685
languageName: unknown
76787686
linkType: soft
76797687

7688+
"react-native-get-random-values@npm:^1.11.0":
7689+
version: 1.11.0
7690+
resolution: "react-native-get-random-values@npm:1.11.0"
7691+
dependencies:
7692+
fast-base64-decode: ^1.0.0
7693+
peerDependencies:
7694+
react-native: ">=0.56"
7695+
checksum: 07729f70a007f7a3b8f98ebf687c1298ba288b87dd71d8ba385be6b5a377718b27b97547bbe1db6b225b83ee109dfce0b01721e6ed535d53892f3ac81e6bf975
7696+
languageName: node
7697+
linkType: hard
7698+
76807699
"react-native-nitro-modules@npm:^0.9.2":
76817700
version: 0.9.2
76827701
resolution: "react-native-nitro-modules@npm:0.9.2"

0 commit comments

Comments
 (0)