crypt_perf.html 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <!DOCTYPE html>
  2. <html>
  3. <!--
  4. Copyright 2009 The Closure Library Authors. All Rights Reserved.
  5. Use of this source code is governed by the Apache License, Version 2.0.
  6. See the COPYING file for details.
  7. -->
  8. <!--
  9. -->
  10. <head>
  11. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  12. <title>Closure Performance Tests - UTF8 encoding and decoding</title>
  13. <link rel="stylesheet" type="text/css"
  14. href="../testing/performancetable.css"/>
  15. <script src="../base.js"></script>
  16. <script>
  17. goog.require('goog.crypt');
  18. goog.require('goog.string');
  19. goog.require('goog.testing.PerformanceTable');
  20. goog.require('goog.testing.jsunit');
  21. </script>
  22. </head>
  23. <body>
  24. <h1>Closure Performance Tests - UTF8 encoding and decoding</h1>
  25. <p>
  26. <strong>User-agent:</strong>
  27. <script>document.write(navigator.userAgent);</script>
  28. </p>
  29. <div id="perfTable"></div>
  30. <hr>
  31. <script>
  32. var table = new goog.testing.PerformanceTable(
  33. goog.dom.getElement('perfTable'));
  34. var STRING_LENGTH = 100000;
  35. function testDecodeAscii() {
  36. var arr = [];
  37. for (var i = 0; i < STRING_LENGTH; i++) {
  38. arr.push(120);
  39. }
  40. table.run(goog.partial(goog.crypt.utf8ByteArrayToString, arr),
  41. 'Decode UTF8 byte array with ASCII characters (1 byte / character)');
  42. }
  43. function testDecodeLatin() {
  44. var arr = [];
  45. for (var i = 0; i < STRING_LENGTH; i++) {
  46. arr.push(195, 182);
  47. }
  48. table.run(goog.partial(goog.crypt.utf8ByteArrayToString, arr),
  49. 'Decode UTF8 byte array with Latin characters (2 bytes / character)');
  50. }
  51. function testDecodeLeftArrow() {
  52. var arr = [];
  53. for (var i = 0; i < STRING_LENGTH; i++) {
  54. arr.push(226, 134, 144);
  55. }
  56. table.run(goog.partial(goog.crypt.utf8ByteArrayToString, arr),
  57. 'Decode UTF8 byte array with left arrows (3 bytes / character)');
  58. }
  59. function testEncodeAscii() {
  60. var str = goog.string.repeat('x', STRING_LENGTH);
  61. table.run(goog.partial(goog.crypt.stringToUtf8ByteArray, str),
  62. 'Encode ASCII string (1 byte / character)');
  63. }
  64. function testEncodeLatin() {
  65. var str = goog.string.repeat('\u00F6', STRING_LENGTH);
  66. table.run(goog.partial(goog.crypt.stringToUtf8ByteArray, str),
  67. 'Encode Latin string (2 bytes / character)');
  68. }
  69. function testEncodeLeftArrow() {
  70. var str = goog.string.repeat('\u2190', STRING_LENGTH);
  71. table.run(goog.partial(goog.crypt.stringToUtf8ByteArray, str),
  72. 'Encode left arrows (3 bytes / character)');
  73. }
  74. </script>
  75. </body>
  76. </html>