-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLexeme.comparaison.htm
More file actions
244 lines (225 loc) · 5.95 KB
/
Lexeme.comparaison.htm
File metadata and controls
244 lines (225 loc) · 5.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
<html>
<head>
<title>Performance des structures de données</title>
<link rel="stylesheet" type="text/css" href="widget/Stats/styles.css">
<style>
CODE, PRE {
background: #EEE;
color: #000;
display: block;
font-weight: bold;
}
H2, H3 {
background: #EEE;
border-bottom: 4px solid #666;
margin: 0;
padding: .25em;
}
B {
font-size: 1.2em;
}
DIV {
margin: 0 0 1em;
}
TABLE {
font-family: 'Monaco','Menlo','Ubuntu Mono','Consolas','source-code-pro',monospace !important;
}
FIELDSET {
float: right;
}
FIELDSET DL {
margin: 0;
}
</style>
</head>
<body>
<a href="index.htm">Index</a>
<h1>Performance des structures de données</h1>
<p>
Les differentes structures sont censés répondre aux mêmes tests unitaires.<br>
Le temps d'execution est la seule chose observée ici.<br>
</p>
<input type="button" id="eTest" onclick="UnitTest()" value="test">
<input type="input" id="eRepeat" value="10" size="3"> fois
<fieldset><legend>Attributs</legend>
<dl id="eAttributes">
<dt><input id="eNow" type="checkbox"><label for="eNow">now</label></dt>
<dt><input id="eMin" type="checkbox"><label for="eMin">min</label></dt>
<dt><input id="eMoy" type="checkbox" checked><label for="eMoy">moy</label></dt>
<dt><input id="eMax" type="checkbox"><label for="eMax">max</label></dt>
<dt><input id="eTot" type="checkbox"><label for="eTot">tot</label></dt>
<dt><input id="eSum" type="checkbox"><label for="eSum">sum</label></dt>
</dl>
</fieldset>
<table border="1" id="eTABLE"></table>
<script src="js/framework.js"></script>
<script src="js/shared.js"></script>
<script src="js/lexer.node.object.js"></script>
<script src="js/lexer.node.simple.js"></script>
<!-- Lexeme -->
<script>
var Lexeme
, createLexemeFunction =function( sNodeType ){
var s
switch( sNodeType ){
case 'HTMLElement': s='document.createElement(o.token)'; break;
case 'ObjectNode': s='new Node (o.token)'; break;
case 'SimpleNode': s='new SimpleNode (o.token)'; break;
case 'EmptyObject': s='new EmptyObject (o.token)'; break;
default: throw Error ('Invalid Lexeme Type.')
}
Lexeme = new Function ( 'o',
'var m = '+ s +';'
+'m.oValue=o;'
+'return m;'
)
}
EmptyObject=(function(){ // C'est pas une solution !
var OO =function(){}
OO.prototype ={
// Lexer
nodeName:null,
nodeType:null,
parentNode:null,
firstChild:null,
lastChild:null,
previousSibling:null,
nextSibling:null,
appendChild: function(){},
getElementsByTagName:function(){},
hasChildNodes: function(){},
removeChild: function(){},
// Incremental Lexer
insertBefore: function(){}
}
return OO
})()
</script>
<!-- Stats -->
<script src="widget/Stats/scripts.js"></script>
<script>
_('eAttributes,eNow,eMin,eMoy,eMax,eTot,eSum')
Stats.print.union({
now: eNow.checked,
min: eMin.checked,
moy: eMoy.checked,
max: eMax.checked,
tot: eTot.checked,
sum: eSum.checked
})
Stats.getTime =function( n ){
return (n*1000).toFixed(2) +' µs'
}
Stats.getName =function( sNodeType, nId ){
return sNodeType + nId
}
var displayAttr =function( evt ){
var e = Events.element( evt )
Stats.print[ e.nextSibling.innerHTML ] = e.checked
UnitTest()
eTest.focus()
}
Events.add( 'click',
eNow, displayAttr,
eMin, displayAttr,
eMoy, displayAttr,
eMax, displayAttr,
eTot, displayAttr,
eSum, displayAttr
)
</script>
<script>
_('eTest,eRepeat,eTABLE')
var oChrono = new Chrono (), oResult
var aLexemeType = ['HTMLElement','ObjectNode','SimpleNode'] // ,'EmptyObject'
var CompareTests =function( nId ){
var a = Array.merge( aLexemeType, [])
for(var i=0; a[i]; i++) a[i] = Stats.getName(a[i], nId )
for(var i=0, ni=a.length; i<ni; i++){
if( _( a[0] )) _( a[0]).innerHTML = Stats.compare.apply( Stats, a )
a.push( a.shift())
}
}
var aTests =(function(){
var o1, o2, o3
return [
{name:'new',test:function(){ o1 = Lexeme ({token:'STRING'}) }},
{name:'',test:function(){ o2 = new Lexeme ({token:'STRING'}) }},
{name:'',test:function(){ o3 = new Lexeme ({token:'STRING'}) }},
{name:'appendChild',test:function(){ o1.appendChild( o2 ) }},
{name:'',test:function(){
var nChild = 5
var nDepth = 3
var appendNodes=function( oP, n ){
if( n<nDepth )
for(var i=0; i<nChild; i++ )
oP.appendChild(
appendNodes( Lexeme({ token:'STRING'+ (i>1?i:'') }), n+1 )
)
return oP
}
appendNodes( o1, 0 )
}},
{name:'getElementsByTagName',test:function(){
o1.lastChild.getElementsByTagName('STRING')
}},
{name:'hasChildNodes',test:function(){ o1.hasChildNodes() }},
{name:'insertBefore',test:function(){ o1.insertBefore( o3, o2 ) }},
{name:'removeChild',test:function(){ o1.removeChild( o2 ) }},
{name:'',test:function(){ o1 = o2 = o3 = null }}
]
})()
UnitTest=function(){
var nLimit = eRepeat.value
for(var j=0; aLexemeType[j]; j++){
var sNodeType = aLexemeType[j]
createLexemeFunction( sNodeType )
for(var i=0; i<nLimit; i++)
for(var k=0; aTests[k]; k++)
UnitTest.test( Stats.getName( sNodeType, k ), k )
}
UnitTest.show()
}
UnitTest.init =function( sNodeType, nId ){
var eTR = Tag('TR'), eTH
for(var j=0; aLexemeType[j]; j++){
var sNodeType = aLexemeType[j]
eTH = eTR.appendChild( Tag('TH', {
id:'e'+sNodeType,
innerHTML:'<h2>'+sNodeType+'</h2>'
}))
}
eTABLE.appendChild( eTR )
for(var k=0; aTests[k]; k++){
if( aTests[k].name ){
eTABLE.appendChild( Tag('TR', { innerHTML:'<th colspan="'+ aLexemeType.length +'"><h3><code>'+ aTests[k].name +'</code></h3></th>' }))
eTR = Tag('TR')
for(var j=0; aLexemeType[j]; j++){
eTR.appendChild( Tag('TD', { id: Stats.getName( aLexemeType[j], k )}))
}
eTABLE.appendChild( eTR )
}
}
}
UnitTest.test =function( sName, nId ){
var nTime
oChrono.start()
aTests[nId].test()
nTime = oChrono.stop()
Stats.set( sName, nTime )
}
UnitTest.show =function(){
for(var i=0; aTests[i]; i++) CompareTests( i )
}
UnitTest.init()
UnitTest()
var nTime=0
var nInterval = setInterval(
function(){
if( ++nTime == 20 ) clearInterval( nInterval )
else UnitTest()
}, 200 )
eTest.focus()
</script>
</body>
</html>