我试图比较从 python 获取 Cypher 查询的执行时间,即在 neo4j 服务器上计算所需的时间(不包括输出结果所需的时间)。现在我正在使用以下代码:
from neo4j.v1 import
driver = GraphDatabase.driver('bolt://localhost:7687', auth=('neo4j', '1234'))
n_repeats = 3
cypher = "MATCH (a) -[:{}*]- (b) WHERE ID(a) < ID(b) RETURN DISTINCT a, b".format(graphname + '_edges')
with driver.session() as session:
total_time = 0
for _ in range(n_repeats):
with session.begin_transaction() as tx:
start = time.time()
tx.run(cypher)
total_time += time.time() - start
avg_time = total_time*1000 / n_repeats
print('Average execution time:', avg_time, 'ms')
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法来计算密码查询的执行时间?例如,在 postgresql 中,有 EXPLAIN ANALYZE 语句,它还提供了执行 SQL 查询所需的时间。在 Cypher 中有 EXPLAIN 和 …