HTML Preparation code:
x
 
1
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
2
<div id="maincontainer">
3
                             <div class="container">
4
    <div class="row">
5
        <div class="col-md-12">
6
             <h1>Long service leave</h1>
7
        </div>
8
    </div>
9
</div>
10
<article class="content-page">
11
    <div class="container">
12
        <div class="row">
13
            
14
            <div class="col-md-8 articleContent">
15
                
16
<div id="content_container_540237">
17
<h2 id="What-is-long-service-leave">What is long service leave</h2><h2 id="Entitlement-(not-mining-employees)">Entitlement (not mining employees)</h2><h2 id="Continuous-employment">Continuous employment</h2><h2 id="Cashing-in-long-service-leave">Cashing-in long service leave</h2><h2 id="Payment-for-long-service-leave">Payment for long service leave</h2><h2 id="Casual-and-part-time-employees">Casual and part-time employees</h2>
18
</div>
19
20
                <span class="updated">Updated:  13th September 2019</span>
21
                                        
22
                                </div>
23
            
24
            <div class="col-md-4 rightHandMenu">
25
                <div class="pagewidget">
26
                    <div class="pagewidget__controls">
27
                        <button class="pagewidget__favourite" id="item_540235">
28
                            <i class="far fa-heart"></i>
29
                            <span>Add favourite</span></button>
30
                         
31
                        
32
                            <i class="fas fa-heart"></i>
33
                            <span>1</span></a>
34
                         
35
                         <button class="pagewidget__print" onclick="window.print()">
36
                            <i class="fas fa-print"></i>
37
                            <span>Print<span>
38
                         </span></span></button>
39
                    </div>
40
                    <div class="link-list related-links" id="onThisPage">
41
                        <h2 class="pagewidget__heading">On this page</h2>
42
                        <ul></ul>
43
                    </div>
44
                </div>
45
             </div>
46
             
47
        </div>
48
    </div>  
49
</article>
50
51
              </div>
Script Preparation code:
 
    var list = $('#onThisPage ul');
    $(".articleContent h2").each(function() {
      //  $(this).prepend('<a id="' + $(this).text().replace(/ /g,'-') + '"></a>');
        $(this).attr('id', $(this).text().replace(/ /g,'-'));
        $(list).append('<li><a href="#' + $(this).text().replace(/ /g,'-') + '">' +  $(this).text() + '</a></li>');
        
    });
Tests:
  • c1

     
    $("#maincontainer .articleContent h2").each(function() {
            $(this).attr('id', $(this).text().replace(/ /g,'-'));
            $(list).append('<li><a href="#' + $(this).text().replace(/ /g,'-') + '">' +  $(this).text() + '</a></li>');
    });
  • c2

     
    $("#maincontainer h2").each(function() {
            $(this).attr('id', $(this).text().replace(/ /g,'-'));
            $(list).append('<li><a href="#' + $(this).text().replace(/ /g,'-') + '">' +  $(this).text() + '</a></li>');
    });
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    c1
    c2

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 5 years ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36
Chrome 77 on Windows
View result in a separate tab
Test name Executions per second
c1 580.0 Ops/sec
c2 297.6 Ops/sec