FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
ClearScript/ClearScriptBenchmarks/SunSpider.cs at master · orudge/ClearScript · GitHub
orudge
/
ClearScript
Public
forked from
ClearFoundry/ClearScript
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
ClearScript
/
ClearScriptBenchmarks
/
SunSpider.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
151 lines (129 loc) · 5.32 KB
Breadcrumbs
ClearScript
/
ClearScriptBenchmarks
/
SunSpider.cs
Copy path
File metadata and controls
151 lines (129 loc) · 5.32 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using
System
;
using
System
.
Collections
.
Generic
;
using
System
.
Diagnostics
;
using
System
.
Linq
;
using
System
.
Net
;
using
System
.
Text
;
namespace
Microsoft
.
ClearScript
.
Test
{
internal
static
class
SunSpider
{
private
const
string
version
=
"sunspider-1.0.2"
;
private
const
string
baseUrl
=
"https://webkit.org/perf/"
+
version
+
"/"
+
version
+
"/"
;
private
const
int
repeatCount
=
10
;
private
const
string
scriptBegin
=
"<script>"
;
private
const
string
scriptEnd
=
"</script>"
;
private
static
bool
gotCode
;
private
static
string
testPrefix
;
private
static
string
testContents
;
public
static
void
RunSuite
(
ScriptEngine
engine
)
{
// download raw test code if necessary
if
(
!
gotCode
)
{
Console
.
Write
(
"Downloading code... "
)
;
testPrefix
=
DownloadFileAsString
(
"sunspider-test-prefix.js"
)
;
testContents
=
DownloadFileAsString
(
"sunspider-test-contents.js"
)
;
Console
.
WriteLine
(
"Done"
)
;
gotCode
=
true
;
}
// set up dummy HTML DOM
var
mockDOM
=
new
MockDOM
(
)
;
engine
.
AccessContext
=
typeof
(
SunSpider
)
;
engine
.
AddHostObject
(
"document"
,
mockDOM
)
;
engine
.
AddHostObject
(
"window"
,
mockDOM
)
;
engine
.
AddHostObject
(
"parent"
,
mockDOM
)
;
// load raw test code
engine
.
Execute
(
testPrefix
)
;
engine
.
Execute
(
testContents
)
;
engine
.
Execute
(
@"
function ClearScriptCleanup() {
delete Array.prototype.toJSONString;
delete Boolean.prototype.toJSONString;
delete Date.prototype.toJSONString;
delete Number.prototype.toJSONString;
delete Object.prototype.toJSONString;
}
"
)
;
// initialize
var
testCount
=
(
int
)
engine
.
Script
.
tests
.
length
;
var
testIndices
=
Enumerable
.
Range
(
0
,
testCount
)
.
ToList
(
)
;
var
repeatIndices
=
Enumerable
.
Range
(
0
,
repeatCount
)
.
ToList
(
)
;
// run warmup cycle
Console
.
Write
(
"Warming up... "
)
;
testIndices
.
ForEach
(
testIndex
=>
RunTest
(
engine
,
mockDOM
,
testIndex
)
)
;
Console
.
WriteLine
(
"Done"
)
;
// run main test
var
results
=
repeatIndices
.
Select
(
index
=>
new
Dictionary
<
string
,
int
>
(
)
)
.
ToArray
(
)
;
repeatIndices
.
ForEach
(
repeatIndex
=>
{
Console
.
Write
(
"Running iteration {0}... "
,
repeatIndex
+
1
)
;
testIndices
.
ForEach
(
testIndex
=>
{
var
name
=
(
string
)
engine
.
Script
.
tests
[
testIndex
]
;
results
[
repeatIndex
]
[
name
]
=
RunTest
(
engine
,
mockDOM
,
testIndex
)
;
}
)
;
Console
.
WriteLine
(
"Done"
)
;
}
)
;
// show results
var
resultString
=
new
StringBuilder
(
"{
\"
v
\"
:
\"
"
+
version
+
"
\"
,"
)
;
results
[
0
]
.
Keys
.
ToList
(
)
.
ForEach
(
name
=>
{
resultString
.
Append
(
"
\"
"
+
name
+
"
\"
:["
)
;
resultString
.
Append
(
string
.
Join
(
","
,
repeatIndices
.
Select
(
repeatIndex
=>
results
[
repeatIndex
]
[
name
]
)
)
)
;
resultString
.
Append
(
"],"
)
;
}
)
;
resultString
.
Length
-=
1
;
resultString
.
Append
(
"}"
)
;
Process
.
Start
(
(
new
Uri
(
baseUrl
+
"results.html?"
+
resultString
)
)
.
AbsoluteUri
)
;
}
private
static
int
RunTest
(
ScriptEngine
engine
,
MockDOM
mockDOM
,
int
index
)
{
// extract test script
var
name
=
(
string
)
engine
.
Script
.
tests
[
index
]
;
var
html
=
(
string
)
engine
.
Script
.
testContents
[
index
]
;
var
start
=
html
.
IndexOf
(
scriptBegin
,
StringComparison
.
OrdinalIgnoreCase
)
+
scriptBegin
.
Length
;
var
end
=
html
.
IndexOf
(
scriptEnd
,
StringComparison
.
OrdinalIgnoreCase
)
;
var
script
=
html
.
Substring
(
start
,
end
-
start
)
;
// execute test
var
result
=
int
.
MinValue
;
mockDOM
.
RecordAction
=
value
=>
result
=
value
;
engine
.
Execute
(
name
,
script
)
;
engine
.
Script
.
ClearScriptCleanup
(
)
;
return
result
;
}
private
static
string
DownloadFileAsString
(
string
name
)
{
using
(
var
client
=
new
WebClient
(
)
)
{
return
client
.
DownloadString
(
baseUrl
+
name
)
;
}
}
// ReSharper disable InconsistentNaming
// ReSharper disable UnusedMember.Local
// ReSharper disable UnusedParameter.Local
private
class
MockDOM
{
public
Action
<
int
>
RecordAction
{
private
get
;
set
;
}
public
object
getElementById
(
string
id
)
{
return
this
;
}
public
string
innerHTML
{
get
;
set
;
}
public
object
parent
{
get
{
return
this
;
}
}
public
void
recordResult
(
int
time
)
{
RecordAction
(
time
)
;
}
public
object
onerror
{
get
;
set
;
}
}
// ReSharper restore UnusedParameter.Local
// ReSharper restore UnusedMember.Local
// ReSharper restore InconsistentNaming
}
}
Back
|
FazBrowse Home
|
New Git URL