No Description

benchmark.js 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import RNTest from './react-native-testkit/'
  2. import React from 'react'
  3. import RNFetchBlob from 'react-native-fetch-blob'
  4. import {
  5. Text,
  6. View,
  7. Platform,
  8. Dimensions,
  9. Image,
  10. } from 'react-native';
  11. const fs = RNFetchBlob.fs
  12. const { Assert, Comparer, Info, prop } = RNTest
  13. const describe = RNTest.config({
  14. group : '0.8.0',
  15. run : true,
  16. expand : true,
  17. timeout : 10000,
  18. })
  19. const { TEST_SERVER_URL, TEST_SERVER_URL_SSL, FILENAME, DROPBOX_TOKEN, styles } = prop()
  20. const dirs = RNFetchBlob.fs.dirs
  21. describe('upload BASE64 v.s. Storage', (report, done) => {
  22. let b64data = null
  23. let storageFile = dirs.DocumentDir + '/benchmark-1mb'
  24. let b64res, storageRes
  25. let iteration = 50
  26. RNFetchBlob
  27. .config({ path : storageFile })
  28. .fetch('get', `${TEST_SERVER_URL}/public/1mb-dummy`)
  29. .then((res) => res.readFile('base64'))
  30. .then((data) => {
  31. b64data = data
  32. report(
  33. <Info key="test data should correct">
  34. <Text>size of b64data = {data.length}</Text>
  35. </Info>)
  36. b64Test()
  37. })
  38. // base64 upload benchmark
  39. function b64Test() {
  40. let p = Promise.resolve()
  41. let begin = Date.now()
  42. let count = 0
  43. for(let i=0; i< iteration; i++) {
  44. p = p.then(() => {
  45. if(++count <iteration)
  46. return RNFetchBlob.fetch('POST', `${TEST_SERVER_URL}/echo`, {}, b64data)
  47. else {
  48. b64res = Date.now() - begin
  49. storageTest()
  50. }
  51. })
  52. }
  53. }
  54. // storage upload benchmark
  55. function storageTest() {
  56. let p = Promise.resolve()
  57. let begin = Date.now()
  58. let count = 0
  59. for(let i=0; i< iteration; i++) {
  60. p = p.then(() => {
  61. if(++count < iteration)
  62. return RNFetchBlob.fetch('POST', `${TEST_SERVER_URL}/echo`, {}, RNFetchBlob.wrap(storageFile))
  63. else {
  64. storageRes = Date.now() - begin
  65. summary()
  66. }
  67. })
  68. }
  69. }
  70. function summary() {
  71. report(
  72. <Info key="BASE64">
  73. <Text>{`BASE64 ${b64res/iteration} ms/req`}</Text>
  74. </Info>,
  75. <Info key="Storage">
  76. <Text>{`Storage ${storageRes/iteration} ms/req`}</Text>
  77. </Info>)
  78. done()
  79. }
  80. })