@@ -16,21 +16,22 @@ const describe = RNTest.config({
16
16
group : '0.8.0' ,
17
17
run : true ,
18
18
expand : true ,
19
- timeout : 10000 ,
19
+ timeout : 999999999 ,
20
20
} )
21
21
const { TEST_SERVER_URL , TEST_SERVER_URL_SSL , FILENAME , DROPBOX_TOKEN , styles } = prop ( )
22
22
const dirs = RNFetchBlob . fs . dirs
23
23
24
- describe ( 'upload BASE64 v.s. Storage' , ( report , done ) => {
24
+ false && describe ( 'upload BASE64 v.s. Storage' , ( report , done ) => {
25
25
26
26
let b64data = null
27
- let storageFile = dirs . DocumentDir + '/benchmark-1mb '
27
+ let storageFile = dirs . DocumentDir + '/benchmark-cache '
28
28
let b64res , storageRes
29
29
let iteration = 50
30
+ let target = `${ TEST_SERVER_URL } /public/1mb-dummy`
30
31
31
32
RNFetchBlob
32
33
. config ( { path : storageFile } )
33
- . fetch ( 'get' , ` ${ TEST_SERVER_URL } /public/1mb-dummy` )
34
+ . fetch ( 'get' , target )
34
35
. then ( ( res ) => res . readFile ( 'base64' ) )
35
36
. then ( ( data ) => {
36
37
b64data = data
@@ -48,8 +49,13 @@ describe('upload BASE64 v.s. Storage', (report, done) => {
48
49
let count = 0
49
50
for ( let i = 0 ; i < iteration ; i ++ ) {
50
51
p = p . then ( ( ) => {
51
- if ( ++ count < iteration )
52
+ if ( ++ count < iteration ) {
53
+ report (
54
+ < Info key = "benchmark progress" uid = "report" >
55
+ < Text style = { { textAlign :'center' } } > BASE64 { count } /{ iteration } </ Text >
56
+ </ Info > )
52
57
return RNFetchBlob . fetch ( 'POST' , `${ TEST_SERVER_URL } /echo` , { } , b64data )
58
+ }
53
59
else {
54
60
b64res = Date . now ( ) - begin
55
61
storageTest ( )
@@ -65,8 +71,13 @@ describe('upload BASE64 v.s. Storage', (report, done) => {
65
71
let count = 0
66
72
for ( let i = 0 ; i < iteration ; i ++ ) {
67
73
p = p . then ( ( ) => {
68
- if ( ++ count < iteration )
74
+ if ( ++ count < iteration ) {
75
+ report (
76
+ < Info key = "benchmark progress" uid = "report" >
77
+ < Text style = { { textAlign :'center' } } > Storage { count } /{ iteration } </ Text >
78
+ </ Info > )
69
79
return RNFetchBlob . fetch ( 'POST' , `${ TEST_SERVER_URL } /echo` , { } , RNFetchBlob . wrap ( storageFile ) )
80
+ }
70
81
else {
71
82
storageRes = Date . now ( ) - begin
72
83
summary ( )
@@ -87,3 +98,127 @@ describe('upload BASE64 v.s. Storage', (report, done) => {
87
98
}
88
99
89
100
} )
101
+
102
+
103
+ false && describe ( 'write file BASE64 v.s. URI' , ( report , done ) => {
104
+ let iteration = 200
105
+ let target = `${ TEST_SERVER_URL } /public/6mb-dummy`
106
+ let sourceURI = dirs . DocumentDir + '/benchmark2-source'
107
+ let sourceBASE64 = null
108
+ let b64Res = 0
109
+ let uriRes = 0
110
+ RNFetchBlob . fetch ( 'GET' , target )
111
+ . then ( ( res ) => {
112
+ sourceBASE64 = res . base64 ( )
113
+ return fs . writeFile ( sourceURI , res . base64 ( ) , 'base64' )
114
+ } )
115
+ . then ( ( ) => {
116
+ let p = Promise . resolve ( )
117
+ let begin = Date . now ( )
118
+ let count = 0
119
+ for ( let i = 0 ; i < iteration ; i ++ ) {
120
+ p = p . then ( ( ) => {
121
+ if ( ++ count < iteration ) {
122
+ report (
123
+ < Info key = "benchmark progress" uid = "report2" >
124
+ < Text style = { { textAlign :'center' } } > BASE64 { count } /{ iteration } </ Text >
125
+ </ Info > )
126
+ return fs . writeFile ( dirs . DocumentDir + '/benchmark2-target' , sourceBASE64 , 'base64' )
127
+ }
128
+ else {
129
+ b64Res = Date . now ( ) - begin
130
+ uriTest ( )
131
+ }
132
+ } )
133
+ }
134
+ } )
135
+
136
+ function uriTest ( ) {
137
+ let p = Promise . resolve ( )
138
+ let begin = Date . now ( )
139
+ let count = 0
140
+ for ( let i = 0 ; i < iteration ; i ++ ) {
141
+ p = p . then ( ( ) => {
142
+ if ( ++ count < iteration ) {
143
+ report (
144
+ < Info key = "benchmark progress" uid = "report2" >
145
+ < Text style = { { textAlign :'center' } } > URI { count } /{ iteration } </ Text >
146
+ </ Info > )
147
+ return fs . writeFile ( dirs . DocumentDir + '/benchmark2-target' , sourceURI , 'uri' )
148
+ }
149
+ else {
150
+ uriRes = Date . now ( ) - begin
151
+ summary ( )
152
+ }
153
+ } )
154
+ }
155
+ }
156
+
157
+ function summary ( ) {
158
+ report (
159
+ < Info key = "BASE64 - writeFile" >
160
+ < Text > { `BASE64 ${ b64Res / iteration } ms/req` } </ Text >
161
+ </ Info > ,
162
+ < Info key = "URI - writeFile" >
163
+ < Text > { `URI ${ uriRes / iteration } ms/req` } </ Text >
164
+ </ Info > )
165
+ done ( )
166
+ }
167
+
168
+ } )
169
+
170
+
171
+ describe ( 'read file benchmark' , ( report , done ) => {
172
+
173
+ let iteration = 200
174
+ let target = `${ TEST_SERVER_URL } /public/6mb-dummy`
175
+ let source = dirs . DocumentDir + '/benchmark3-source'
176
+ let res = { }
177
+ RNFetchBlob . fetch ( 'GET' , target )
178
+ . then ( ( res ) => {
179
+ return fs . writeFile ( source , res . base64 ( ) , 'base64' )
180
+ } )
181
+ . then ( ( ) => {
182
+ test ( 'base64' , ( ) => {
183
+ test ( 'ascii' , ( ) => {
184
+ test ( 'utf8' , summary )
185
+ } )
186
+ } )
187
+ } )
188
+
189
+ function test ( encode , cb ) {
190
+ let p = Promise . resolve ( )
191
+ let begin = Date . now ( )
192
+ let count = 0
193
+ for ( let i = 0 ; i < iteration ; i ++ ) {
194
+ p = p . then ( ( ) => {
195
+ if ( ++ count < iteration ) {
196
+ report (
197
+ < Info key = "benchmark progress" uid = "report3" >
198
+ < Text style = { { textAlign :'center' } } > { encode } { count } /{ iteration } </ Text >
199
+ </ Info > )
200
+ return fs . readFile ( source , encode )
201
+ }
202
+ else {
203
+ res [ encode ] = Date . now ( ) - begin
204
+ cb ( )
205
+ }
206
+ } )
207
+ }
208
+ }
209
+
210
+ function summary ( ) {
211
+ report (
212
+ < Info key = "BASE64 - readFile" >
213
+ < Text > { `BASE64 ${ res [ 'base64' ] / iteration } ms/req` } </ Text >
214
+ </ Info > ,
215
+ < Info key = "ASCII - readFile" >
216
+ < Text > { `ASCII ${ res [ 'ascii' ] / iteration } ms/req` } </ Text >
217
+ </ Info > ,
218
+ < Info key = "UTF8 - readFile" >
219
+ < Text > { `UTF8 ${ res [ 'utf8' ] / iteration } ms/req` } </ Text >
220
+ </ Info > )
221
+ done ( )
222
+ }
223
+
224
+ } )
0 commit comments