-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
223 lines (215 loc) · 8.29 KB
/
index.html
File metadata and controls
223 lines (215 loc) · 8.29 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Node 22 + Express / SQLite Performance Test</title>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
font-family: Arial, sans-serif;
background-color: white;
margin: 0;
padding: 0;
}
main {
display: flex;
min-height: 100vh;
width: 100%;
max-width: 1200px;
flex-direction: column;
padding: 2.5rem;
}
h1 {
font-weight: bold;
font-size: 1.25rem;
margin-bottom: 1.5rem;
}
p {
margin-bottom: 2.5rem;
line-height: 1.4em;
}
a {
color: #2563eb;
text-decoration: none;
text-underline-offset: 4px;
}
.container {
display: flex;
flex-direction: column;
gap: 1.5rem;
}
@media (min-width: 640px) {
.container {
flex-direction: row;
gap: 2.5rem;
}
}
.card {
background-color: white;
padding: 1.5rem;
border-radius: 0.5rem;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
flex: 1;
margin-bottom: 1rem;
}
.card h2 {
font-size: 1.125rem;
font-weight: 600;
margin-bottom: 0;
}
.spinner {
width: 20px;
height: 20px;
margin-top: 1rem;
border: 2px solid #f3f3f3;
border-top: 2px solid #2563eb;
border-radius: 50%;
animation: spin 1s linear infinite;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.flex-row {
display: flex;
flex-direction: row;
align-items: center;
gap: 0.25rem;
}
.navbar {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
background-color: #f3f4f6;
padding: 0.5rem;
border-radius: 0.25rem;
border: 1px solid #d3d3d3;
margin-bottom: 1.5rem;
}
.navbar a {
text-decoration: none;
color: #4b5563;
padding: 0.5rem 1rem;
border-radius: 0.25rem;
border: 1px solid #d3d3d3;
transition: background-color 0.3s ease;
margin: 0.25rem;
}
.navbar a:hover {
background-color: #d1d5db;
color: black !important;
}
.navbar a.active {
background-color: #2563eb;
border: 1px solid #2563eb;
color: white !important;
}
</style>
</head>
<body>
<main>
<nav class="navbar">
<a href="https://php-sqlite.xpressionist.com">PHP / SQLite Test</a>
<a href="https://node-sqlite.xpressionist.com" class="active">Node / SQLite Test</a>
<a href="https://nextjs-sqlite.xpressionist.com">Next.js / SQLite Test</a>
<a href="https://sveltekit-sqlite.xpressionist.com">SvelteKit / SQLite Test</a>
</nav>
<h1>Node 22.7.0 + Express / SQLite Performance Test</h1>
<p>
Built by <a href="https://x.com/fedeandri">@fedeandri</a> starting from
<a href="https://x.com/ashleyrudland/status/1826991719646179583"
target="_blank"
rel="noopener noreferrer">@ashleyrudland</a>'s PHP code. See the <strong>source</strong> of this
<a href="https://github.com/fedeandri/node-sqlite"
target="_blank"
rel="noopener noreferrer">Node / SQLite Test on Github</a>.
<br /> <s>From my SQLite tests <strong>PHP writes are ~10x faster and reads are ~40x faster</strong> than Node.</s>
<br />NEW RESULTS: <strong>Node writes are ~2x faster</strong> than PHP and <strong>PHP reads are ~1.2x faster</strong> than Node.
<br />--
<br />I wanted to run more comprehensive tests, so I added updates and deletes. Then, to test a scenario closer to real life usage, I added indexes, more data variation, and tweaked SQLite for better data durability other than pure performance (thanks to <a href="https://x.com/jasonleowsg" target="_blank" rel="noopener noreferrer">@jasonleowsg</a> for pointing me to <a href="https://x.com/meln1k/status/1813314113705062774" target="_blank" rel="noopener noreferrer">this post</a>). For Node-based apps, I switched from sqlite3 to <a href="https://www.npmjs.com/package/better-sqlite3" target="_blank" rel="noopener noreferrer">better-sqlite3</a> (thanks to <a href="https://x.com/theSlavenIvanov" target="_blank" rel="noopener noreferrer">@theSlavenIvanov</a> for the recommendation), and this really levels the playing field.
</p>
<div class="container">
<div class="card">
<h2>Node / SQLite Test</h2>
<small>(5 minutes cache)</small>
<div id="results-box">
<div class="flex-row">
<div class="spinner"></div>
<span>Running test (<span id="runningTime">0.0</span>s)...</span>
</div>
</div>
</div>
<div class="card">
<h2>VPS Specs</h2>
<small>(<a href="https://www.vultr.com/pricing/" target="_blank">Vultr High Performance Intel $12/mo</a> with <a href="https://www.cloudpanel.io/" target="_blank">CloudPanel</a>)</small>
<div id="specs-box">
<div class="flex-row">
<div class="spinner"></div>
<span>Loading specs data...</span>
</div>
</div>
</div>
</div>
</main>
<script>
document.addEventListener('DOMContentLoaded', function () {
let startTime;
let timer;
function updateRunningTime() {
if (startTime) {
let runningTime = (Date.now() - startTime) / 1000;
document.getElementById('runningTime').textContent = runningTime.toFixed(1);
}
}
function getSpecs() {
fetch('/api/getSpecs')
.then(response => response.json())
.then(result => {
let content = '<ul>';
for (let [key, value] of Object.entries(result)) {
content += `<li>${key}: ${value}</li>`;
}
content += '</ul>';
document.getElementById('specs-box').innerHTML = content;
})
.catch(error => {
document.getElementById('specs-box').innerHTML = `<p>Error: ${error}</p>`;
});
}
function runTest() {
startTime = Date.now();
timer = setInterval(updateRunningTime, 200);
fetch('/api/runTest')
.then(response => response.json())
.then(result => {
clearInterval(timer);
let content = '<ul>';
content += `<li>Duration: ${result.duration ? result.duration.toLocaleString() : 'N/A'} seconds</li>`;
content += `<li>DB size: ${result.dbSizeInMb ? (result.dbSizeInMb >= 1024 ? (result.dbSizeInMb / 1024).toLocaleString(undefined, { maximumFractionDigits: 1 }) + 'GB' : result.dbSizeInMb.toLocaleString() + 'MB') : 'N/A'}</li>`;
content += `<li>Total operations: ${result.totalOperations ? result.totalOperations.toLocaleString() : 'N/A'}</li>`;
content += `<li>Operations/sec: ${result.operationsPerSecond ? result.operationsPerSecond.toLocaleString() : 'N/A'}</li>`;
content += `<li>Writes: ${result.writes ? result.writes.toLocaleString() : 'N/A'}</li>`;
content += `<li>Writes/sec: ${result.writesPerSecond ? result.writesPerSecond.toLocaleString() : 'N/A'}</li>`;
content += `<li>Reads: ${result.reads ? result.reads.toLocaleString() : 'N/A'}</li>`;
content += `<li>Reads/sec: ${result.readsPerSecond ? result.readsPerSecond.toLocaleString() : 'N/A'}</li>`;
content += `<li>Updates: ${result.updates ? result.updates.toLocaleString() : 'N/A'}</li>`;
content += `<li>Updates/sec: ${result.updatesPerSecond ? result.updatesPerSecond.toLocaleString() : 'N/A'}</li>`;
content += `<li>Deletes: ${result.deletes ? result.deletes.toLocaleString() : 'N/A'}</li>`;
content += `<li>Deletes/sec: ${result.deletesPerSecond ? result.deletesPerSecond.toLocaleString() : 'N/A'}</li>`;
content += '</ul>';
document.getElementById('results-box').innerHTML = content;
})
.catch(error => {
clearInterval(timer);
document.getElementById('results-box').innerHTML = `<p>Error: ${error}</p>`;
});
}
runTest();
getSpecs();
});
</script>
</body>
</html>