Код: Выделить всё
static def measureSaxon(String xml, String xpath) {
Processor processor = new Processor(false);
processor.setConfigurationProperty(FeatureKeys.OPTIMIZATION_LEVEL, "0")
XdmNode xdm = processor.newDocumentBuilder().build(new StreamSource(new StringReader(xml)));
def compiler = processor.newXPathCompiler()
return measureExecutionTime(
"Saxon",
xpath,
{
def evaluate = compiler.evaluate(xpath, xdm)
if (evaluate instanceof XdmValue && evaluate.size() > 0) {
return evaluate.itemAt(0).getStringValue()
} else {
return "No node found"
}
}
)
}
< /code>
Тем не менее, первый вызов всегда намного медленнее, чем последующие вызовы, которые, по -видимому, извлекают выгоду из какого -либо кэширования или оптимизации, даже хотя я пробовал: < /p>
processor.setConfigurationProperty(FeatureKeys.OPTIMIZATION_LEVEL, "0")
< /code>
Ниже приведены мои контрольные результаты. Вы можете увидеть, как первый вызов может быть очень медленным, а последующие вызовы намного быстрее: < /p>
# Benchmark Results for Saxon
| XPath Expression | Execution Time (ns) | Execution Time (ms) | Result |
|---------------------------------|---------------------|---------------------|----------------------|
| `/program/@name` | 151562270 | 151.56227 | j$Collections |
| `/program/objects/o/@base` | 522288 | 0.522288 | some.class |
| `/program/objects/o/o/o/o/@base`| 12328695 | 12.328695 | org.lang.bytes |
Подробнее здесь: https://stackoverflow.com/questions/793 ... benchmarks
Мобильная версия