speed.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. (function() {
  2. var numbers = [];
  3. for (var i=0; i<1000; i++) numbers.push((Math.random() * (1000*i)));
  4. var strings = $.map(numbers, function(num){ return accounting.formatMoney(num*1000, "HK$ "); });
  5. JSLitmus.test('unformat()', function(count) {
  6. var i = 0;
  7. while ( count-- ) {
  8. accounting.unformat(strings[i])
  9. i++;
  10. i > strings.length && (i = 0);
  11. }
  12. });
  13. JSLitmus.test('unformat(array)', function(count) {
  14. var i = 0;
  15. while ( count-- ) {
  16. accounting.unformat([strings[i], strings[i+1]]);
  17. i += 2;
  18. i > numbers.length && (i = 0);
  19. }
  20. });
  21. JSLitmus.test('toFixed()', function(count) {
  22. while ( count-- ) {
  23. accounting.toFixed(count*1000, 2);
  24. }
  25. });
  26. JSLitmus.test('formatNumber()', function(count) {
  27. var i = 0;
  28. while ( count-- ) {
  29. accounting.formatNumber(numbers[i]);
  30. i++;
  31. i > numbers.length && (i = 0);
  32. }
  33. });
  34. JSLitmus.test('formatNumber(array)', function(count) {
  35. var i = 0;
  36. while ( count-- ) {
  37. accounting.formatNumber([numbers[i], numbers[i+1]]);
  38. i += 2;
  39. i > numbers.length && (i = 0);
  40. }
  41. });
  42. JSLitmus.test('formatMoney()', function(count) {
  43. var i = 0;
  44. while ( count-- ) {
  45. accounting.formatMoney(numbers[i]);
  46. i++;
  47. i > numbers.length && (i = 0);
  48. }
  49. });
  50. JSLitmus.test('formatMoney(array)', function(count) {
  51. var i = 0;
  52. while ( count-- ) {
  53. accounting.formatMoney([numbers[i], numbers[i+1]]);
  54. i += 2;
  55. i > numbers.length && (i = 0);
  56. }
  57. });
  58. JSLitmus.test('formatColumn()', function(count) {
  59. var i = 0;
  60. while ( count-- ) {
  61. accounting.formatColumn([numbers[i], numbers[i+1]]);
  62. i += 2;
  63. i > numbers.length && (i = 0);
  64. }
  65. });
  66. })();