-
-
Notifications
You must be signed in to change notification settings - Fork 654
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add timing/benchmarking fascility and UI (#1128)
- Loading branch information
1 parent
0688b9b
commit 00eec20
Showing
9 changed files
with
113 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* @flow */ | ||
import React, { PureComponent } from 'react'; | ||
import { StyleSheet, View } from 'react-native'; | ||
import format from 'date-fns/format'; | ||
import differenceInMilliseconds from 'date-fns/difference_in_milliseconds'; | ||
|
||
import { RawLabel } from '../common'; | ||
|
||
const styles = StyleSheet.create({ | ||
item: { | ||
padding: 16, | ||
borderBottomWidth: 1, | ||
borderColor: 'rgba(127, 127, 127, 0.25)', | ||
}, | ||
label: { | ||
fontWeight: 'bold', | ||
}, | ||
value: { | ||
opacity: 0.9, | ||
}, | ||
}); | ||
|
||
export default class TimeItem extends PureComponent { | ||
props: { | ||
text: string, | ||
start: Date, | ||
end: Date, | ||
}; | ||
|
||
render() { | ||
const { text, start, end } = this.props; | ||
const startStr = format(start, 'HH:mm:ss'); // eslint-disable-line | ||
const durationStr = differenceInMilliseconds(end, start); | ||
const timingStr = `Start: ${startStr} Duration: ${durationStr} ms`; | ||
|
||
return ( | ||
<View style={styles.item}> | ||
<RawLabel style={styles.label} text={text} /> | ||
<RawLabel style={styles.value} text={timingStr} /> | ||
</View> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* @flow */ | ||
import React, { PureComponent } from 'react'; | ||
import { FlatList } from 'react-native'; | ||
|
||
import { Screen } from '../common'; | ||
import TimeItem from './TimeItem'; | ||
import timing from '../utils/timing'; | ||
|
||
export default class TimingScreen extends PureComponent { | ||
render() { | ||
return ( | ||
<Screen title="Timing"> | ||
<FlatList | ||
data={timing.log} | ||
keyExtractor={item => item} | ||
renderItem={({ item }) => <TimeItem text={item.text} start={item.start} end={item.end} />} | ||
/> | ||
</Screen> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* @flow */ | ||
import { TimingItem } from '../types'; | ||
|
||
const timingMap = {}; | ||
const log: TimingItem[] = []; | ||
|
||
const start = (key: string) => { | ||
timingMap[key] = Date.now(); | ||
}; | ||
|
||
const end = (key: string) => { | ||
if (timingMap[key]) { | ||
log.push({ | ||
text: key, | ||
start: timingMap[key], | ||
end: Date.now(), | ||
}); | ||
delete timingMap[key]; | ||
} else { | ||
log.push({ | ||
text: key, | ||
end: Date.now(), | ||
}); | ||
} | ||
}; | ||
|
||
export default { | ||
start, | ||
end, | ||
log, | ||
}; |