Hi,

The root traversal of a traversal is the one whose traversal.getParent() 
instanceof EmptyStep.

In our strategies we use:

traversal.getParent().equals(EmptyStep.instance())
traversal.getParent() == EmptyStep.instance()
traversal.getParent() instanceof EmptyStep

Which way is fastest?

import org.apache.tinkerpop.gremlin.process.traversal.step.util.EmptyStep
random = new Random()
x = []
for(int i=0;i<10000;i++) {
 select = random.nextInt(3)
 if(0 == select)
  x.add(EmptyStep.instance())
 if(1 == select)
  x.add(i)
 else
  x.add(UUID.randomUUID())
}


gremlin> clock(1000){ x.each{ it instanceof EmptyStep }}
==>0.7513385119999999
gremlin> clock(1000){ x.each{ it == EmptyStep }}
==>1.526259428
gremlin> clock(1000){ x.each{ it.equals(EmptyStep) }}
==>2.829880314

Seems “instanceof” is the winner.

Marko.

http://markorodriguez.com



Reply via email to