Skip to content

Commit

Permalink
Create Benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
mrousavy committed May 10, 2022
1 parent 577962a commit 73c4fd9
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 121 deletions.
6 changes: 6 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"presets": ["module:metro-react-native-babel-preset"],
"plugins": [
["@babel/plugin-proposal-decorators", { "legacy": true }]
]
}
115 changes: 0 additions & 115 deletions App.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion __tests__/App-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import 'react-native';
import React from 'react';
import App from '../App';
import App from '../src/App';

// Note: test renderer must be required after react-native.
import renderer from 'react-test-renderer';
Expand Down
4 changes: 0 additions & 4 deletions babel.config.js

This file was deleted.

2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

import {AppRegistry} from 'react-native';
import App from './App';
import App from './src/App';
import {name as appName} from './app.json';

AppRegistry.registerComponent(appName, () => App);
39 changes: 39 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* Generated with the TypeScript template
* https://github.com/react-native-community/react-native-template-typescript
*
* @format
*/

import React, {useCallback} from 'react';
import {
Button,
SafeAreaView,
StatusBar,
StyleSheet,
useColorScheme,
} from 'react-native';

const App = () => {
const isDarkMode = useColorScheme() === 'dark';

const runBenchmarks = useCallback(() => {
console.log('no.');
}, []);

return (
<SafeAreaView style={styles.container}>
<StatusBar barStyle={isDarkMode ? 'light-content' : 'dark-content'} />
<Button title="Run Benchmarks" onPress={runBenchmarks} />
</SafeAreaView>
);
};

const styles = StyleSheet.create({
container: {flex: 1, justifyContent: 'center', alignItems: 'center'},
});

export default App;
9 changes: 9 additions & 0 deletions src/storages/AsyncStorage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import AsyncStorage from '@react-native-async-storage/async-storage';

const key = 'k';

AsyncStorage.setItem(key, 'hello');

export async function getFromAsyncStorage(): Promise<string | null> {
return AsyncStorage.getItem(key);
}
9 changes: 9 additions & 0 deletions src/storages/MMKV.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {MMKV} from 'react-native-mmkv';

const storage = new MMKV();
const key = 'k';
storage.set(key, 'hello');

export function getFromMMKV(): string | undefined {
return storage.getString(key);
}
33 changes: 33 additions & 0 deletions src/storages/SQLite.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import 'react-native-quick-sqlite';

const db = 'myDatabase';

const dbOpenResult = sqlite.open(db, 'databases');

// status === 1, operation failed
if (dbOpenResult.status) {
console.error('SQLite Database could not be opened');
}

let result = sqlite.executeSql(db, 'DROP TABLE IF EXISTS Values', []);
if (!result.status) {
console.log('Created Table Values');
} else {
console.error(result);
}

sqlite.executeSql(
db,
'CREATE TABLE IF NOT EXISTS Values(value VARCHAR(30))',
[],
);
sqlite.executeSql(db, 'INSERT INTO Values (value) VALUES (:value)', ['hello']);

export function getFromSQLite(): string | undefined {
let {status, rows} = sqlite.executeSql(db, 'SELECT * FROM `values`', []);
if (rows == null || rows.length < 1) {
throw new Error(`Failed to get Values! ${JSON.stringify(status)}`);
}

return rows.item(0);
}

0 comments on commit 73c4fd9

Please sign in to comment.