Created
May 10, 2018 23:25
-
-
Save ppazos/77b9acb37093c9e4cad40ffcac776cfe to your computer and use it in GitHub Desktop.
Tests about size and isEmpty to check if a XML node is empty or not.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def root = new XmlSlurper().parseText("""<root> | |
<context> | |
<start_time> | |
<value>[[COMPOSITION_DATE:::DATETIME]]</value> | |
</start_time> | |
<setting> | |
<value>[[COMPOSITION_SETTING_VALUE:::STRING]]</value> | |
<defining_code> | |
<terminology_id> | |
<value>openehr</value> | |
</terminology_id> | |
<code_string>[[COMPOSITION_SETTING_CODE:::STRING]]</code_string> | |
</defining_code> | |
</setting> | |
</context> | |
</root>""") | |
def root2 = new XmlSlurper().parseText("""<root></root>""") | |
def root3 = new XmlSlurper().parseText("""<root><context></context></root>""") | |
def root4 = new XmlSlurper().parseText("""<root> | |
<context> | |
<start_time></start_time> | |
</context> | |
</root>""") | |
println root.context.size() | |
println root2.context.size() | |
println root3.context.size() | |
println root4.context.size() | |
println root.context.isEmpty() | |
println root2.context.isEmpty() | |
println root3.context.isEmpty() | |
println root4.context.isEmpty() | |
println root.context.start_time.size() | |
println root2.context.start_time.size() | |
println root3.context.start_time.size() | |
println root4.context.start_time.size() | |
println root.context.start_time.isEmpty() | |
println root2.context.start_time.isEmpty() | |
println root3.context.start_time.isEmpty() | |
println root4.context.start_time.isEmpty() | |
println root.context.start_time.value.size() | |
println root2.context.start_time.value.size() | |
println root3.context.start_time.value.size() | |
println root4.context.start_time.value.size() | |
println root.context.start_time.value.isEmpty() | |
println root2.context.start_time.value.isEmpty() | |
println root3.context.start_time.value.isEmpty() | |
println root4.context.start_time.value.isEmpty() | |
// performance size vs isEmpty | |
def start_time = System.currentTimeMillis() | |
for (int i = 0; i < 10000; i++) | |
{ | |
root.context.start_time.value.size() | |
root2.context.start_time.value.size() | |
root3.context.start_time.value.size() | |
root4.context.start_time.value.size() | |
} | |
def end_time = System.currentTimeMillis() | |
println end_time - start_time | |
// -------------- | |
start_time = System.currentTimeMillis() | |
for (int i = 0; i < 10000; i++) | |
{ | |
root.context.start_time.value.isEmpty() | |
root2.context.start_time.value.isEmpty() | |
root3.context.start_time.value.isEmpty() | |
root4.context.start_time.value.isEmpty() | |
} | |
end_time = System.currentTimeMillis() | |
println end_time - start_time | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment