-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbenchmark_query.py
117 lines (85 loc) · 3.54 KB
/
benchmark_query.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
"""
Use the `pytest-benchmark` library to more formally benchmark the Neo4j queries wiht warmup and iterations.
`pip install pytest-benchmark`
"""
import os
import pytest
from dotenv import load_dotenv
from neo4j import GraphDatabase
import query
load_dotenv()
@pytest.fixture(scope="session")
def session():
URI = "bolt://localhost:7687"
NEO4J_USER = os.environ.get("NEO4J_USER")
NEO4J_PASSWORD = os.environ.get("NEO4J_PASSWORD")
with GraphDatabase.driver(URI, auth=(NEO4J_USER, NEO4J_PASSWORD)) as driver:
with driver.session(database="neo4j") as session:
yield session
def test_benchmark_query1(benchmark, session):
result = benchmark(query.run_query1, session)
result = result.to_dicts()
assert len(result) == 3
assert result[0]["personID"] == 85723
assert result[1]["personID"] == 68753
assert result[2]["personID"] == 54696
assert result[0]["numFollowers"] == 4998
assert result[1]["numFollowers"] == 4985
assert result[2]["numFollowers"] == 4976
def test_benchmark_query2(benchmark, session):
result = benchmark(query.run_query2, session)
result = result.to_dicts()
assert len(result) == 1
assert result[0]["name"] == "Melissa Murphy"
assert result[0]["numFollowers"] == 4998
assert result[0]["city"] == "Austin"
assert result[0]["state"] == "Texas"
assert result[0]["country"] == "United States"
def test_benchmark_query3(benchmark, session):
result = benchmark(query.run_query3, session, "United States")
result = result.to_dicts()
assert len(result) == 5
assert result[0]["city"] == "Austin"
assert result[1]["city"] == "Kansas City"
assert result[2]["city"] == "Miami"
assert result[3]["city"] == "San Antonio"
assert result[4]["city"] == "Portland"
def test_benchmark_query4(benchmark, session):
result = benchmark(query.run_query4, session, 30, 40)
result = result.to_dicts()
assert len(result) == 3
assert result[0]["countries"] == "United States"
assert result[1]["countries"] == "Canada"
assert result[2]["countries"] == "United Kingdom"
assert result[0]["personCounts"] == 30712
assert result[1]["personCounts"] == 3043
assert result[2]["personCounts"] == 1809
def test_benchmark_query5(benchmark, session):
result = benchmark(query.run_query5, session, "male", "London", "United Kingdom", "fine dining")
result = result.to_dicts()
assert len(result) == 1
assert result[0]["numPersons"] == 52
def test_benchmark_query6(benchmark, session):
result = benchmark(query.run_query6, session, "female", "tennis")
result = result.to_dicts()
assert len(result) == 5
assert result[0]["numPersons"] == 66
assert result[0]["city"] in ("Houston", "Birmingham")
assert result[0]["country"] in ("United States", "United Kingdom")
def test_benchmark_query7(benchmark, session):
result = benchmark(query.run_query7, session, "United States", 23, 30, "photography")
result = result.to_dicts()
assert len(result) == 1
assert result[0]["numPersons"] == 150
assert result[0]["state"] == "California"
assert result[0]["country"] == "United States"
def test_benchmark_query8(benchmark, session):
result = benchmark(query.run_query8, session)
result = result.to_dicts()
assert len(result) == 1
assert result[0]["numPaths"] == 58431994
def test_benchmark_query9(benchmark, session):
result = benchmark(query.run_query9, session, 50, 25)
result = result.to_dicts()
assert len(result) == 1
assert result[0]["numPaths"] == 45633521