如何从 python 获取密码查询的执行时间?
How to get the execution time of a cypher query from python?
我正在尝试比较从 python 获取 Cypher 查询的执行时间,即在 neo4j-server 上计算所需的时间(不包括输出结果所需的时间)。现在我正在使用以下代码:
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')
有没有更好的方法来计算密码查询的执行时间?例如在 postgresql 中有 EXPLAIN ANALYZE 语句,它还提供了执行 SQL 查询所需的时间。在 Cypher 中有 EXPLAIN 和 PROFILE 语句,但两者似乎都没有 return 具体时间。
我现在正在使用 neo4j-driver 连接到 neo4j,但我愿意切换到另一个库。
事实上,所用时间在所有结果中都可用,无需分析。它们位于结果摘要中,执行时间分为任何结果流可用之前的时间和服务器消耗整个结果流之前的时间。
可以将它们相加得到查询的总执行时间,以毫秒表示:
result = tx.run(query, params)
avail = result.summary().result_available_after
cons = result.summary().result_consumed_after
total_time = avail + cons
Neo4j Python 驱动程序 1.7
from neo4j.v1 import
driver = GraphDatabase.driver("bolt://localhost:7687", auth=("neo4j", "password"))
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()
result = tx.run(cypher)
records = list(result) # consume the records
tx.commit()
total_time += time.time() - start
avg_time = total_time*1000 / n_repeats
print('Average execution time:', avg_time, 'ms')
我正在尝试比较从 python 获取 Cypher 查询的执行时间,即在 neo4j-server 上计算所需的时间(不包括输出结果所需的时间)。现在我正在使用以下代码:
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')
有没有更好的方法来计算密码查询的执行时间?例如在 postgresql 中有 EXPLAIN ANALYZE 语句,它还提供了执行 SQL 查询所需的时间。在 Cypher 中有 EXPLAIN 和 PROFILE 语句,但两者似乎都没有 return 具体时间。
我现在正在使用 neo4j-driver 连接到 neo4j,但我愿意切换到另一个库。
事实上,所用时间在所有结果中都可用,无需分析。它们位于结果摘要中,执行时间分为任何结果流可用之前的时间和服务器消耗整个结果流之前的时间。
可以将它们相加得到查询的总执行时间,以毫秒表示:
result = tx.run(query, params)
avail = result.summary().result_available_after
cons = result.summary().result_consumed_after
total_time = avail + cons
Neo4j Python 驱动程序 1.7
from neo4j.v1 import
driver = GraphDatabase.driver("bolt://localhost:7687", auth=("neo4j", "password"))
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()
result = tx.run(cypher)
records = list(result) # consume the records
tx.commit()
total_time += time.time() - start
avg_time = total_time*1000 / n_repeats
print('Average execution time:', avg_time, 'ms')