How to get the exact runtime of an algorithm such as gds.bfs.stream through a script?

I want to test the performance of Neo4j on some large graphs so I need to get the exact runtime of some gds algorithms.

At first, I tried the Neo4j driver in python and the time package to calculate the runtime,but the runtime is very large,which made me confused.And now I think the communication time took the most part of time.

Then I checked out the debug log. I found the timestamps named BFS::start and BFS::finished. Is the difference between two timestamps just the exact runtime of bfs time? How can I use a script to test automatically except reading the debug log file?

The log is like this:

2024-07-15 05:37:43.880+0000 INFO [c.n.g.e.GraphDataScienceExtension] [neo4j.BoltWorker-5 [bolt-3 - /127.0.0.1:53234]] BFS :: Start
2024-07-15 05:37:44.184+0000 INFO [c.n.g.e.GraphDataScienceExtension] [gds-2] BFS 1%
2024-07-15 05:37:44.207+0000 INFO [c.n.g.e.GraphDataScienceExtension] [neo4j.BoltWorker-5 [bolt-3 - /127.0.0.1:53234]] BFS 100%
2024-07-15 05:37:44.207+0000 INFO [c.n.g.e.GraphDataScienceExtension] [neo4j.BoltWorker-5 [bolt-3 - /127.0.0.1:53234]] BFS :: Finished

Python code got 3 seconds but the log file showed the runtime was just 0.32 seconds. And in some other algorithms like WCC or PageRank, the difference can go to 100 times!!

I'll appreciate it if you could help me.^ ^

Is your return payload large? If so, maybe that is the reason for the difference in the log file duration and the python duration.

You could try eliminating the return payload by trying 1) removing 'return' and 'yield' (if it allows', or 2) return a constant 1 (you can't end a query with a 'call' if 'call' is not the entire cypher query)