So I have this piece of code in Jena, that measures the execution time of a select query
Timer timer = new Timer();
timer.startTimer();
Query query = QueryFactory.create(queryString);
QueryExecution qexec = QueryExecutionFactory.create(query,dataset);
ResultSet results = qexec.execSelect();
long endTime = timer.endTimer();
Now the issue is the that this variable endTime
shows a running time result that is smaller than what the query execution time should have been. The dataset
is a Jena TDB location.
To test this out, I ran the same query using Apache Jena's Fuseki on the same TDB store and I find that the execution time is different (maybe the actual execution time). What is the right way to find execution time using Jena. I don't want to execute everything using Fuseki and find the answer.
QueryExecutionFactory.create(query,dataset);
All this does is create an execution that can execute your query, importantly it does not execute your query.
To start execution you need to call one of the execX()
methods which will depend on the query type e.g. execSelect()
for SELECT
queries
Execution in Jena is lazy so in order to time execution you need to actually enumerate the results, execution does not finish until results are fully enumerated e.g.
ResultSet results = qexec.execSelect();
long numResults = ResultSetFormatter.consume(results);
And at that point you can stop your timer