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