What is the best way to check if the size of a store is higher than a particular number? #3734
-
I have a native store and I want to check if my number of triples is higher than a particular number X, should I use size() >= X or a getStatements(null, null, null, false) and test to see if I have at least X statements in the returned iterator. I've tried both with X = 4, try (SailConnection connection = nativeStore.getConnection()) {
int i;
StopWatch timer = new StopWatch();
try (CloseableIteration<? extends Statement, SailException> it = connection.getStatements(null, null, null, false)) {
for (i = 0; i < 4 && it.hasNext(); i++) {
it.next();
}
}
System.out.println((i == 4) + ", " + timer.stopAndShow());
timer.reset();
System.out.println((connection.size() >= 4) + ", " + timer.stopAndShow());
System.out.println(connection.size());
} And the output result is:
With those results I want to use Thanks, ATE |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Size method typically uses getStatements, but needs to iterate over all the statements to count them. Since you are checking for an upper limit, then it will typically be faster to use getStatements the way you are doing because you can stop iterating once you hit your limit. The size method could potentially have a faster implementation on some stores or under certain circumstances, but I don't that we are currently doing anything special here. |
Beta Was this translation helpful? Give feedback.
Size method typically uses getStatements, but needs to iterate over all the statements to count them. Since you are checking for an upper limit, then it will typically be faster to use getStatements the way you are doing because you can stop iterating once you hit your limit.
The size method could potentially have a faster implementation on some stores or under certain circumstances, but I don't that we are currently doing anything special here.