@@ -27,9 +27,11 @@ import io.github.pdvrieze.formats.xmlschema.datatypes.serialization.facets.*
27
27
import io.github.pdvrieze.formats.xmlschema.resolved.SchemaVersion
28
28
import io.github.pdvrieze.formats.xmlschema.resolved.SimpleResolver
29
29
import io.github.pdvrieze.formats.xmlschema.test.TestXSTestSuite.NON_TESTED.*
30
+ import kotlinx.datetime.Instant
30
31
import kotlinx.serialization.KSerializer
31
32
import nl.adaptivity.xmlutil.*
32
33
import nl.adaptivity.xmlutil.XMLConstants.XSD_NS_URI
34
+ import nl.adaptivity.xmlutil.core.KtXmlReader
33
35
import nl.adaptivity.xmlutil.core.impl.newReader
34
36
import nl.adaptivity.xmlutil.jdk.StAXStreamingFactory
35
37
import nl.adaptivity.xmlutil.serialization.XML
@@ -48,65 +50,121 @@ import kotlin.test.assertTrue
48
50
49
51
class TestXSTestSuite {
50
52
51
- var xml: XML = XML {}
53
+ var xml: XML = XML {
54
+ xmlStreaming.setFactory(xmlStreaming.genericFactory)
55
+ recommended_0_87_0()
56
+ }
52
57
53
58
@Test
54
- fun testParseGeneric () {
59
+ fun testParseGenericSpeed () {
60
+ val urls = testXmlSchemaUrls()
61
+ var dummy1: Any?
62
+ var dummy2: Any?
63
+ var dummy3: Any?
64
+ var dummy4: Any?
65
+ measure(" Parse xml ${urls.size} schema documents" ) {
66
+ for ((_, url) in urls) {
67
+ url.openStream().use { instr ->
68
+ KtXmlReader (instr).use { r ->
69
+ for (e in r) {
70
+ when (e) {
71
+ EventType .START_DOCUMENT -> {
72
+ dummy1 = r.version
73
+ dummy2 = r.relaxed
74
+ dummy3 = r.standalone
75
+ }
76
+ EventType .END_ELEMENT ,
77
+ EventType .START_ELEMENT -> {
78
+ for (i in 0 until r.attributeCount) {
79
+ dummy1 = r.localName
80
+ dummy2 = r.namespaceURI
81
+ dummy3 = r.prefix
82
+ dummy4 = r.getAttributeValue(i)
83
+ }
84
+ dummy1 = r.localName
85
+ dummy2 = r.namespaceURI
86
+ dummy3 = r.prefix
87
+ }
88
+ EventType .TEXT ,
89
+ EventType .CDSECT ,
90
+ EventType .ENTITY_REF ,
91
+ EventType .IGNORABLE_WHITESPACE ,
92
+ EventType .PROCESSING_INSTRUCTION ,
93
+ EventType .COMMENT -> {
94
+ dummy1 = r.text
95
+ }
96
+ EventType .DOCDECL -> { dummy1 = r.text}
97
+ EventType .END_DOCUMENT -> {}
98
+ EventType .ATTRIBUTE -> error(" unexpected attribute" )
99
+ }
100
+ }
101
+ }
102
+ }
103
+
104
+ }
105
+ }
106
+ }
107
+
108
+ @Test
109
+ fun testDeserializeGenericSpeed () {
55
110
xml = XML {
56
- isUnchecked = true
111
+ isUnchecked = false
57
112
defaultPolicy {
58
113
autoPolymorphic = true
59
114
throwOnRepeatedElement = true
60
115
}
61
116
}
62
117
xmlStreaming.setFactory(xmlStreaming.genericFactory)
63
- testParseSpeed ()
118
+ testDeserializeSpeed ()
64
119
xmlStreaming.setFactory(null )
65
120
}
66
121
67
122
@Test
68
- fun testParseStax () {
123
+ fun testDeserializeStaxSpeed () {
69
124
xml = XML {
70
125
defaultPolicy {
71
126
autoPolymorphic = true
72
127
throwOnRepeatedElement = true
73
128
}
74
129
}
75
130
xmlStreaming.setFactory(StAXStreamingFactory ())
76
- testParseSpeed ()
131
+ testDeserializeSpeed ()
77
132
xmlStreaming.setFactory(null )
78
133
}
79
134
80
- fun testParseSpeed () {
81
- val suiteURL: URL = javaClass.getResource(" /xsts/suite.xml" )
82
-
83
- val override = javaClass.getResource(" /override.xml" ).withXmlReader {
84
- val compact = xml.decodeFromReader<CompactOverride >(it)
85
- OTSSuite (compact)
135
+ inline fun measure (name : String , rounds : Int = 20, warmups : Int = 1, action : MeasureInfo .() -> Unit ): Long {
136
+ val initTime = System .currentTimeMillis()
137
+ var startTime = initTime
138
+ val iterCount = rounds+ warmups
139
+ for (i in 0 until iterCount) {
140
+ if (i== warmups+ 1 ) {
141
+ startTime = System .currentTimeMillis()
142
+ }
143
+ MeasureInfo (i- warmups, rounds, warmups).action()
86
144
}
145
+ val endTime = System .currentTimeMillis()
146
+ println (" Init: ${Instant .fromEpochMilliseconds(initTime)} " )
147
+ println (" Start: ${Instant .fromEpochMilliseconds(startTime)} " )
148
+ println (" End: ${Instant .fromEpochMilliseconds(endTime)} " )
149
+ if (rounds== 0 ) {
150
+ val duration = (endTime - initTime)/ warmups
151
+ println (" $name : Duration time: $duration ms" )
152
+ return duration
153
+ } else {
154
+ val duration = (endTime - startTime)/ rounds
155
+ val warmupExtra = (startTime - initTime - duration)
156
+ println (" $name : Duration time × $rounds ): $duration ms (+${warmupExtra} ms)" )
157
+ return duration
158
+ }
159
+ }
87
160
88
- val nodes = mutableListOf<DynamicNode >()
89
- val schemaUrls: List <Pair <URL , URL >> = suiteURL.withXmlReader { xmlReader ->
90
- val suite = xml.decodeFromReader<TSTestSuite >(xmlReader)
91
- suite.testSetRefs
92
- // .filter { arrayOf("sunMeta/").any { m -> it.href.contains(m) } }
93
- .flatMap { setRef ->
94
- val setBaseUrl: URL = javaClass.getResource(" /xsts/${setRef.href} " )
95
- val testSet = override .applyTo(setBaseUrl.withXmlReader { r -> xml.decodeFromReader<TSTestSet >(r) })
96
-
97
- val folderName = setRef.href.substring(0 , setRef.href.indexOf(' /' )).removeSuffix(" Meta" )
98
-
99
- val tsName = " $folderName - ${testSet.name} "
161
+ fun testDeserializeSpeed () {
100
162
101
- testSet.testGroups.flatMap { gr ->
102
- gr.schemaTest?.takeIf { it.expected.any { it.validity.parsable } }?.schemaDocuments?.mapNotNull { sd ->
103
- (setBaseUrl to setBaseUrl.resolve(sd.href))
104
- } ? : emptyList()
105
- }
106
- }
107
- }// .filter { it.second.toString().contains("wildcards") }
163
+ val schemaUrls: List <Pair <URL , URL >> =
164
+ testXmlSchemaUrls()// .filter { it.second.toString().contains("wildcards") }
108
165
109
166
val xml = this .xml.copy {
167
+ isUnchecked = true
110
168
defaultPolicy {
111
169
autoPolymorphic = true
112
170
throwOnRepeatedElement = true
@@ -116,13 +174,9 @@ class TestXSTestSuite {
116
174
}
117
175
assertTrue(xml.config.isUnchecked)
118
176
119
- val initTime = System .currentTimeMillis()
120
- var startTime = initTime
121
- val iterCount = 10
122
-
123
- for (i in 0 .. iterCount) {
124
- if (i == 1 ) startTime = System .currentTimeMillis()
125
-
177
+ print (" Iterating: " )
178
+ val duration = measure(" Parsing and deserializing ${schemaUrls.size} schema documents" ) {
179
+ if (round< 0 ) print (" *" ) else if (round+ 1 < rounds) print (" ×" ) else println (" ×" )
126
180
for ((setBaseUri, uri) in schemaUrls) {
127
181
val resolver = SimpleResolver (xml, setBaseUri)
128
182
try {
@@ -132,17 +186,37 @@ class TestXSTestSuite {
132
186
}
133
187
}
134
188
}
135
- val endTime = System .currentTimeMillis()
136
- val duration = (endTime- startTime)/ iterCount.coerceAtLeast(1 )
189
+ println ()
190
+ assertTrue(duration< 10000 , " Duration expected less than 10 seconds" )
191
+ }
137
192
138
- if (iterCount== 0 ) {
139
- println (" Duration time (${schemaUrls.size} documents): $duration ms" )
140
- } else {
141
- val initialTime = startTime- initTime
142
- println (" Duration time (${schemaUrls.size} documents × $iterCount ): $duration ms (+${initialTime- duration} ms)" )
193
+ private fun testXmlSchemaUrls (): List <Pair <URL , URL >> {
194
+ val suiteURL: URL = javaClass.getResource(" /xsts/suite.xml" )
143
195
196
+ val override = javaClass.getResource(" /override.xml" ).withXmlReader {
197
+ val compact = xml.decodeFromReader<CompactOverride >(it)
198
+ OTSSuite (compact)
199
+ }
200
+
201
+ return suiteURL.withXmlReader { xmlReader ->
202
+ val suite = xml.decodeFromReader<TSTestSuite >(xmlReader)
203
+ suite.testSetRefs
204
+ // .filter { arrayOf("sunMeta/").any { m -> it.href.contains(m) } }
205
+ .flatMap { setRef ->
206
+ val setBaseUrl: URL = javaClass.getResource(" /xsts/${setRef.href} " )
207
+ val testSet = override .applyTo(setBaseUrl.withXmlReader { r -> xml.decodeFromReader<TSTestSet >(r) })
208
+
209
+ val folderName = setRef.href.substring(0 , setRef.href.indexOf(' /' )).removeSuffix(" Meta" )
210
+
211
+ val tsName = " $folderName - ${testSet.name} "
212
+
213
+ testSet.testGroups.flatMap { gr ->
214
+ gr.schemaTest?.takeIf { it.expected.any { it.validity.parsable } }?.schemaDocuments?.mapNotNull { sd ->
215
+ (setBaseUrl to setBaseUrl.resolve(sd.href))
216
+ } ? : emptyList()
217
+ }
218
+ }
144
219
}
145
- assertTrue(duration< 10000 , " Duration expected less than 10 seconds" )
146
220
}
147
221
148
222
@DisplayName(" Test suites: suite.xml" )
@@ -715,3 +789,5 @@ inline fun <R> URL.withXmlReader(body: (XmlReader) -> R): R {
715
789
fun URL.resolve (path : String ): URL {
716
790
return URL (this , path)
717
791
}
792
+
793
+ data class MeasureInfo (val round : Int , val rounds : Int , val warmups : Int )
0 commit comments