@@ -2,29 +2,37 @@ import React, { Component } from 'react';
2
2
import {
3
3
Text ,
4
4
View ,
5
- TouchableOpacity
5
+ TouchableOpacity ,
6
+ NativeModules
6
7
} from 'react-native' ;
7
8
8
- const STRESSFUL_STRING_LENGTH = 48000 ; // Min: 32000
9
- const STRESSFUL_EVENTS_COUNT = 570 ; // Min: 380
9
+ const NativeModule = NativeModules . NativeModule ;
10
10
11
- function buildStringByLength ( length ) {
12
- str = "" ;
13
- charcode = 65 ;
14
- for ( let i = 0 ; i < length ; i ++ ) {
15
- str += String . fromCharCode ( charcode ) ;
16
- charcode ++ ;
17
- if ( charcode == 91 ) charcode = 65 ;
11
+ const BRIDGE_ONEWAY_CALLS = 10 ;
12
+ const BRIDGE_ONEWAY_STR_CHUNK_LEN = 20 ;
13
+ const BRIDGE_TWOWAY_CALLS = 10 ;
14
+ const BRIDGE_TWOWAY_STR_CHUNK_LEN = 20 ;
15
+ const BRIDGE_SETSTATE_STR_CHUNK_LEN = 20 ;
16
+ const EVENT_LOOP_COUNT = 10 ;
17
+ const EVENT_LOOP_STR_CHUNK_LEN = 20 ;
18
+
19
+ function getStringByLength ( chunks ) {
20
+ let res = '' ;
21
+ for ( let i = 0 ; i < chunks ; i ++ ) {
22
+ res += 'EqtCfLH6DYnLT4WjBcLfR9M33uxSEEBMphVSTnpKpEfHCBNn3oxVMpEQ0Rzqlx8BiiyCIF5WnkEhJyGsGhHtVfjgwCueY0DQXmat' ;
18
23
}
19
- return str ;
24
+ return res ;
20
25
}
21
26
22
27
export default class StressScreen extends Component {
28
+
23
29
constructor ( props ) {
24
30
super ( props ) ;
25
31
this . state = {
26
- greeting : undefined ,
27
- passToBridge : undefined
32
+ phase1 : undefined ,
33
+ phase2 : undefined ,
34
+ extraData : undefined ,
35
+ counter : 1
28
36
} ;
29
37
}
30
38
@@ -37,56 +45,102 @@ export default class StressScreen extends Component {
37
45
}
38
46
39
47
render ( ) {
40
- if ( this . state . greeting ) return this . renderAfterButton ( ) ;
48
+ if ( this . state . phase2 ) return this . renderPhase2 ( ) ;
49
+ if ( this . state . phase1 ) return this . renderPhase1 ( ) ;
41
50
return (
42
51
< View style = { { flex : 1 , paddingTop : 20 , justifyContent : 'center' , alignItems : 'center' } } >
43
- < Text style = { { fontSize : 25 , marginBottom : 30 } } >
44
- Welcome
45
- </ Text >
46
- { this . renderTestButton ( 'Say Hello' , this . onButtonPress . bind ( this , 'Hello' ) ) }
47
- { this . renderTestButton ( 'Say World' , this . onButtonPress . bind ( this , 'World' ) ) }
48
- { this . renderTestButton ( 'Bridge Stress' , this . bridgeStressButtonPressed . bind ( this , 'Hello World' ) ) }
49
- { this . renderTestButton ( 'Events Stress' , this . eventsStressButtonPressed . bind ( this , 'Hello World' ) ) }
52
+ { this . renderTestButton ( 'Bridge OneWay Stress' , this . bridgeOneWayStressButtonPressed . bind ( this ) ) }
53
+ { this . renderTestButton ( 'Bridge TwoWay Stress' , this . bridgeTwoWayStressButtonPressed . bind ( this ) ) }
54
+ { this . renderTestButton ( 'Bridge setState Stress' , this . bridgeSetStateStressButtonPressed . bind ( this ) ) }
55
+ { this . renderTestButton ( 'EventLoop Stress' , this . eventLoopStressButtonPressed . bind ( this ) ) }
56
+ { this . renderTestButton ( `Consecutive Stress ${ this . state . counter } ` , this . consecutiveStressButtonPressed . bind ( this ) ) }
50
57
</ View >
51
58
) ;
52
59
}
53
- renderAfterButton ( ) {
60
+
61
+ renderPhase2 ( ) {
54
62
return (
55
63
< View style = { { flex : 1 , paddingTop : 20 , justifyContent : 'center' , alignItems : 'center' } } >
56
- < Text style = { { fontSize : 10 , width : 0 , height : 0 } } >
57
- Bridge: { this . state . passToBridge }
58
- </ Text >
59
- < Text style = { { fontSize : 25 } } >
60
- { this . state . greeting } !!!
64
+ < Text style = { { fontSize : 25 , marginBottom : 20 } } >
65
+ { this . state . phase2 }
61
66
</ Text >
67
+ {
68
+ ! this . state . extraData ? false :
69
+ < Text style = { { fontSize : 10 , width : 100 , height : 20 } } >
70
+ Extra Data: { this . state . extraData }
71
+ </ Text >
72
+ }
62
73
</ View >
63
74
) ;
64
75
}
65
76
66
- onButtonPress ( greeting ) {
77
+ renderPhase1 ( ) {
78
+ return (
79
+ < View style = { { flex : 1 , paddingTop : 20 , justifyContent : 'center' , alignItems : 'center' } } >
80
+ < TouchableOpacity onPress = { this . onButtonPress . bind ( this ) } >
81
+ < Text style = { { color : 'blue' , marginBottom : 20 } } > Next</ Text >
82
+ </ TouchableOpacity >
83
+ </ View >
84
+ ) ;
85
+ }
86
+
87
+ onButtonPress ( ) {
88
+ this . setState ( {
89
+ phase2 : this . state . phase1
90
+ } ) ;
91
+ }
92
+
93
+ bridgeOneWayStressButtonPressed ( ) {
67
94
this . setState ( {
68
- greeting : greeting
95
+ phase1 : 'BridgeOneWay'
96
+ } ) ;
97
+ setImmediate ( ( ) => {
98
+ const str = getStringByLength ( BRIDGE_ONEWAY_STR_CHUNK_LEN ) ;
99
+ for ( let i = 0 ; i < BRIDGE_ONEWAY_CALLS ; i ++ ) {
100
+ NativeModule . echoWithoutResponse ( str ) ;
101
+ }
69
102
} ) ;
70
103
}
71
104
72
- bridgeStressButtonPressed ( greeting ) {
73
- this . onButtonPress ( greeting )
105
+ bridgeTwoWayStressButtonPressed ( ) {
106
+ this . setState ( {
107
+ phase1 : 'BridgeTwoWay'
108
+ } ) ;
109
+ setImmediate ( ( ) => {
110
+ const str = getStringByLength ( BRIDGE_TWOWAY_STR_CHUNK_LEN ) ;
111
+ for ( let i = 0 ; i < BRIDGE_TWOWAY_CALLS ; i ++ ) {
112
+ NativeModule . echoWithResponse ( str ) ;
113
+ }
114
+ } ) ;
115
+ }
74
116
75
- const data = buildStringByLength ( STRESSFUL_STRING_LENGTH ) ;
117
+ bridgeSetStateStressButtonPressed ( ) {
76
118
this . setState ( {
77
- passToBridge : data ,
78
- greeting : greeting
119
+ phase1 : 'BridgeSetState'
120
+ } ) ;
121
+ setImmediate ( ( ) => {
122
+ const str = getStringByLength ( BRIDGE_SETSTATE_STR_CHUNK_LEN ) ;
123
+ this . setState ( {
124
+ extraData : str
125
+ } ) ;
79
126
} ) ;
80
127
}
81
128
82
- eventsStressButtonPressed ( greeting ) {
83
- // Stress:
84
- for ( let i = 0 ; i < STRESSFUL_EVENTS_COUNT ; i ++ ) {
85
- let myString = "" ;
86
- setImmediate ( ( ) => { myString = buildStringByLength ( 1000 ) } ) ;
129
+ eventLoopStressButtonPressed ( ) {
130
+ this . setState ( {
131
+ phase1 : 'EventLoop'
132
+ } ) ;
133
+ for ( let i = 0 ; i < EVENT_LOOP_COUNT ; i ++ ) {
134
+ setImmediate ( ( ) => {
135
+ let str = getStringByLength ( EVENT_LOOP_STR_CHUNK_LEN ) ;
136
+ } ) ;
87
137
}
138
+ }
88
139
89
- setImmediate ( ( ) => { this . onButtonPress ( greeting ) } ) ;
140
+ consecutiveStressButtonPressed ( ) {
141
+ this . setState ( {
142
+ counter : this . state . counter + 1
143
+ } ) ;
90
144
}
91
145
92
146
}
0 commit comments