public static <T> int sizeOf(final Iterable<T> iterable) {
        if (iterable instanceof Collection) {
            return ((Collection<T>) iterable).size();
        } else if (iterable instanceof SizableIterable) {
            return ((SizableIterable<T>) iterable).size();
        } else {
            int size = 0;
            for (Iterator<T> iter = iterable.iterator(); iter.hasNext(); iter.next()) {
                size++;
            }
            return size;
        }
    }
Utility method to determine the number of elements in an Iterable.
<p/>
Checks if the given Iterable is an instance of a Collection or SizableIterable before iterating to improve performance.

@return The size of the given Iterable.
gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/algorithm/generator/SizableIterable.java