testCase.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * @file TestCase is the class for each test case of EChart
  3. * @author Wenli Zhang
  4. */
  5. define(function (require) {
  6. /**
  7. * set up test case
  8. *
  9. * @param {string} name name of test case
  10. * @param {Object} option ECharts option
  11. */
  12. function TestCase(name, option) {
  13. this.name = name;
  14. this.option = option;
  15. }
  16. /**
  17. * run test case and return elapsed time
  18. *
  19. * @param {iterations} iterations number of iterations
  20. * @return {number} elapsed time
  21. */
  22. TestCase.prototype.runTime = function (iterations) {
  23. // run for multi times
  24. var total = 0;
  25. for (var i = 0; i < iterations; ++i) {
  26. total += runTime(this.option);
  27. }
  28. return total / iterations;
  29. };
  30. function runTime(option) {
  31. var container = document.createElement('div');
  32. container.style.width = '800px';
  33. container.style.height = '600px';
  34. var start = new Date();
  35. var chart = echarts.init(container);
  36. chart.setOption(option);
  37. var end = new Date();
  38. chart.dispose();
  39. return end - start;
  40. }
  41. return TestCase;
  42. });