Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

91 lines
2.0KB

  1. const cpp_code = `
  2. #include <cmath>
  3. #include <cheerp/client.h>
  4. #include <cheerp/clientlib.h>
  5. class [[cheerp::jsexport]] JsBridge
  6. {
  7. public:
  8. JsBridge() = default;
  9. size_t test()
  10. {
  11. volatile size_t counter = 0;
  12. for (int i = 0; i < 50000; ++i) {
  13. for (int j = 0; j < 50000; ++j) {
  14. counter++;
  15. }
  16. }
  17. return sqrt(counter);
  18. }
  19. };
  20. void webMain() {}
  21. `.trim();
  22. const html_code = `
  23. <html>
  24. <head>
  25. <script>
  26. function test() {
  27. var counter = 0
  28. for (var i = 0; i < 50000; ++i) {
  29. for (var j = 0; j < 50000; ++j) {
  30. counter++;
  31. }
  32. }
  33. return Math.sqrt(counter);
  34. }
  35. function benchmark() {
  36. var jsBridge = new JsBridge();
  37. {
  38. document.write("Running native JS..<br>");
  39. var start = new Date().getTime();
  40. var ret = test();
  41. var time = new Date().getTime() - start;
  42. document.write("Result: " + ret + "<br>");
  43. document.write("Execution time: " + (time / 1000.0) + " secs<br>");
  44. }
  45. document.write("<br>");
  46. {
  47. document.write("Running compiled JS..<br>");
  48. var start = new Date().getTime();
  49. var ret = jsBridge.test();
  50. var time = new Date().getTime() - start;
  51. document.write("Result: " + ret + "<br>");
  52. document.write("Execution time: " + (time / 1000.0) + " secs<br>");
  53. }
  54. }
  55. </script>
  56. </head>
  57. <body>
  58. Benchmark started... <br/><br/>
  59. <script>
  60. benchmark();
  61. </script>
  62. <br/>
  63. Benchmark finished... <br/>
  64. </body>
  65. </html>`.trim();
  66. const js_code = ``.trim();
  67. const flags = `
  68. -cheerp-pretty-code
  69. -cheerp-no-type-optimizer
  70. -cheerp-no-native-math
  71. -cheerp-no-math-imul
  72. -cheerp-no-math-fround
  73. -O3
  74. -target cheerp`.trim()
  75. const wasm_code = '';
  76. export const example = {
  77. title: 'JS vs Compiled JS perf',
  78. cpp_code: cpp_code,
  79. js_code: js_code,
  80. wasm_code: wasm_code,
  81. html_code: html_code,
  82. flags: flags
  83. }