-
Notifications
You must be signed in to change notification settings - Fork 555
/
Copy pathdbtest.py
72 lines (56 loc) · 2 KB
/
dbtest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import time
from neo4j import GraphDatabase
# Database configurations
neo4j_configurations = [
{
'name': 'Neo4j Config 1',
'NEO4J_URI': 'neo4j+s://73b760b4.databases.neo4j.io',
'NEO4J_USERNAME': 'neo4j',
'NEO4J_PASSWORD': 'HqwAzfG83XwcEQ-mvEG4yNpcRTHMpsgZaYW3qIGJh2I'
},
# {
# 'name': 'Neo4j Config 2',
# 'uri': 'bolt://another-host:7687',
# 'user': 'neo4j',
# 'password': 'password2'
# }
]
# Function to create a Neo4j driver
def create_driver(uri, user, password):
return GraphDatabase.driver(uri, auth=(user, password))
# Function to clear the database
def clear_database(driver):
with driver.session() as session:
session.run("MATCH (n) DETACH DELETE n")
# Performance test function
def performance_test(driver, query, num_operations):
with driver.session() as session:
start_time = time.time()
for i in range(num_operations):
session.run(query, parameters={"id": i, "name": f"name_{i}"})
end_time = time.time()
return end_time - start_time
# Query to execute
query = "CREATE (n:Person {id: $id, name: $name})"
# Number of operations to perform
num_operations = 1000
def dbtest_main():
results = []
for config in neo4j_configurations:
print(f"Testing {config['name']}...")
# Create driver
driver = create_driver(config['uri'], config['user'], config['password'])
# Clear database before test
clear_database(driver)
# Run performance test
elapsed_time = performance_test(driver, query, num_operations)
# Store result
results.append((config['name'], elapsed_time))
# Close driver
driver.close()
print(f"{config['name']} completed in {elapsed_time:.4f} seconds")
print("\nPerformance Test Results:")
for name, time_taken in results:
print(f"{name}: {time_taken:.4f} seconds")
if __name__ == "__main__":
dbtest_main()