Skip to content

Instantly share code, notes, and snippets.

@zetavg
Last active May 22, 2024 00:56
Show Gist options
  • Save zetavg/6f1d27ca5c9a401a69a0b2d637ecdd00 to your computer and use it in GitHub Desktop.
Save zetavg/6f1d27ca5c9a401a69a0b2d637ecdd00 to your computer and use it in GitHub Desktop.
import { useEffect } from 'react';
import registerRootComponent from 'expo/build/launch/registerRootComponent';
/* PASTE THE CODE HERE */
function App() {
useEffect(() => {
const timer = setTimeout(() => {
const iterations = 1e6;
const start = performance.now();
for (let i = 0; i < iterations; i++) {
fn();
}
const end = performance.now();
console.log(`${end - start}ms`);
}, 1000);
return () => {
clearTimeout(timer);
};
}, [fn]);
return null;
}
registerRootComponent(App);
import { useEffect } from 'react';
import { runOnUI } from 'react-native-reanimated';
import registerRootComponent from 'expo/build/launch/registerRootComponent';
/* PASTE THE CODE HERE, WITH 'worklet' inserted in fn. */
function test() {
'worklet';
const iterations = 1e6;
const start = performance.now();
for (let i = 0; i < iterations; i++) {
fn();
}
const end = performance.now();
console.log(`${end - start}ms`);
}
function App() {
useEffect(() => {
const timer = setTimeout(() => {
runOnUI(test)();
}, 1000);
return () => {
clearTimeout(timer);
};
}, [fn]);
return null;
}
registerRootComponent(App);
const obj = {
a: 1,
b: 2,
c: 3,
d: 4,
};
function fn() {
return obj.a;
}
const obj = {
a: 1,
b: 2,
c: 3,
d: 4,
};
const { a } = obj;
function fn() {
return a;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment