Debian Codegraph @

www/public/test/manual/manual-perf.html

raw symbols SCIP
1 <html lang="en">
2 <head>
3 <meta charset="utf-8" />
4 <title>Mocha Tests</title>
5 <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6 <link rel="stylesheet" href="../../node_modules/mocha/mocha.css" />
7 </head>
8 <body style="padding:20px;font-family: sans-serif">
9 <div id="mocha"></div>
10 <script src="../../node_modules/chai/chai.js"></script>
11 <script src="../../node_modules/mocha/mocha.js"></script>
12 <script src="../../node_modules/sinon/pkg/sinon.js"></script>
13 <script src="../../src/htmx.js"></script>
14 <script class="mocha-init">
15 mocha.setup('bdd');
16 mocha.checkLeaks();
17 should = chai.should();
18 </script>
19
20 <script src="../util/util.js"></script>
21 <script>
22 describe("Manual Perf Tests", function() {
23
24 beforeEach(function () {
25 this.server = makeServer();
26 clearWorkArea();
27 });
28 afterEach(function () {
29 this.server.restore();
30 clearWorkArea();
31 });
32
33 function stringRepeat(str, num) {
34 num = Number(num);
35
36 var result = '';
37 while (true) {
38 if (num & 1) { // (1)
39 result += str;
40 }
41 num >>>= 1; // (2)
42 if (num <= 0) break;
43 str += str;
44 }
45
46 return result;
47 }
48
49 it("DOM processing should be fast", function(){
50 this.server.respondWith("GET", "/test", "Clicked!");
51
52 // create an entry with a large content string (256k) and see how fast we can write and read it
53 // to local storage as a single entry
54 var str = stringRepeat("<div>", 30) + stringRepeat("<div><div><span><button hx-get='/test'> Test Get Button </button></span></div></div>\n", 500) + stringRepeat("</div>", 30);
55 var start = performance.now();
56 var stuff = make(str);
57 var end = performance.now();
58 var timeInMs = end - start;
59
60 // make sure the DOM actually processed
61 var firstBtn = stuff.querySelector("button");
62 firstBtn.click();
63 this.server.respond();
64 firstBtn.innerHTML.should.equal("Clicked!");
65
66 chai.assert(timeInMs < 100, "Should take less than 100ms on most platforms, took: " + timeInMs + "ms");
67 })
68
69 });
70 </script>
71
72
73 <script class="mocha-exec">
74 mocha.run();
75 </script>
76 <em>Work Area</em>
77 <hr/>
78 <div id="work-area" hx-history-elt>
79 </div>
80 </body>
81 </html>