-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Praneeth Bedapudi <praneeth@bpraneeth.com>
- Loading branch information
1 parent
97875db
commit 2fff799
Showing
4 changed files
with
860 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>KVIndex benchmarks</title> | ||
|
||
<!-- Recommended meta tags --> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width,initial-scale=1.0"> | ||
|
||
<!-- PyScript CSS --> | ||
<link rel="stylesheet" href="https://pyscript.net/releases/2023.12.1/core.css"> | ||
|
||
<!-- This script tag bootstraps PyScript --> | ||
<script type="module" src="https://pyscript.net/releases/2023.12.1/core.js"></script> | ||
</head> | ||
|
||
<body> | ||
<script type="py" src="./main.py" config="./pyscript.toml" terminal></script> | ||
|
||
<div id="mpl"></div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
import time | ||
|
||
from liteindex import KVIndex | ||
from diskcache import Index | ||
from pyscript import display | ||
|
||
kv_index = KVIndex("kv.db") | ||
dc_index = Index("dc", eviction_policy="none") | ||
|
||
TIMES = { | ||
"insert": { | ||
"liteindex": 0, | ||
"diskcache": 0 | ||
}, | ||
"update_existing": { | ||
"liteindex": 0, | ||
"diskcache": 0 | ||
}, | ||
"read": { | ||
"liteindex": 0, | ||
"diskcache": 0 | ||
}, | ||
"iterate": { | ||
"liteindex": 0, | ||
"diskcache": 0, | ||
}, | ||
"delete": { | ||
"liteindex": 0, | ||
"diskcache": 0, | ||
} | ||
} | ||
|
||
N = 10000 | ||
print(f"Benching small string keys and values, {N} items") | ||
|
||
print("Liteindex: KVIndex Insert test running") | ||
# insert | ||
s = time.time() | ||
for _ in range(1, N): | ||
_ = str(_) | ||
kv_index[_] = _ | ||
TIMES["insert"]["liteindex"] = (time.time() - s)/N | ||
|
||
print("Diskcache: Index Insert test running") | ||
s = time.time() | ||
for _ in range(1, N): | ||
_ = str(_) | ||
dc_index[_] = _ | ||
TIMES["insert"]["diskcache"] = (time.time() - s)/N | ||
|
||
print("Liteindex: KVIndex Update Existing test running") | ||
# update existing | ||
s = time.time() | ||
for _ in range(1, N): | ||
_ = str(_ + 1) | ||
kv_index[_] = _ | ||
TIMES["update_existing"]["liteindex"] = (time.time() - s)/N | ||
|
||
print("Diskcache: Index Update Existing test running") | ||
s = time.time() | ||
for _ in range(1, N): | ||
_ = str(_ + 1) | ||
dc_index[_] = _ | ||
TIMES["update_existing"]["diskcache"] = (time.time() - s)/N | ||
|
||
print("Liteindex: KVIndex Read test running") | ||
# read | ||
s = time.time() | ||
for _ in range(1, N): | ||
_ = str(_) | ||
_ = kv_index[_] | ||
TIMES["read"]["liteindex"] = (time.time() - s)/N | ||
|
||
print("Diskcache: Index Read test running") | ||
s = time.time() | ||
for _ in range(1, N): | ||
_ = str(_) | ||
_ = dc_index[_] | ||
TIMES["read"]["diskcache"] = (time.time() - s)/N | ||
|
||
print("Liteindex: KVIndex Iterate test running") | ||
# iterate items | ||
s = time.time() | ||
for _ in kv_index.items(): | ||
pass | ||
TIMES["iterate"]["liteindex"] = (time.time() - s)/N | ||
|
||
print("Diskcache: Index Iterate test running") | ||
s = time.time() | ||
for _ in dc_index.items(): | ||
pass | ||
TIMES["iterate"]["diskcache"] = (time.time() - s)/N | ||
|
||
print("Liteindex: KVIndex Delete test running") | ||
# delete | ||
s = time.time() | ||
for _ in range(1, N): | ||
_ = str(_) | ||
del kv_index[_] | ||
TIMES["delete"]["liteindex"] = (time.time() - s)/N | ||
|
||
print("Diskcache: Index Delete test running") | ||
s = time.time() | ||
for _ in range(1, N): | ||
_ = str(_) | ||
del dc_index[_] | ||
TIMES["delete"]["diskcache"] = (time.time() - s)/N | ||
|
||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
# Extract operations and their respective times for liteindex and diskcache | ||
operations = list(TIMES.keys()) | ||
liteindex_times = [TIMES[op]["liteindex"] * 1000 for op in operations] | ||
diskcache_times = [TIMES[op]["diskcache"] * 1000 for op in operations] | ||
|
||
# Setting the positions and width for the bars | ||
pos = np.arange(len(operations)) | ||
bar_width = 0.35 | ||
|
||
# Create subplots | ||
fig, ax = plt.subplots() | ||
|
||
# Plotting the bars | ||
ax.bar(pos, liteindex_times, bar_width, label='Liteindex', color='blue') | ||
ax.bar(pos + bar_width, diskcache_times, bar_width, label='Diskcache', color='green') | ||
|
||
# Adding labels and title | ||
ax.set_xlabel('Operations') | ||
ax.set_ylabel('Time (ms)') | ||
ax.set_title('Avg time in milliseconds per operation') | ||
ax.set_xticks(pos + bar_width / 2) | ||
ax.set_xticklabels(operations) | ||
|
||
# Adding a legend | ||
ax.legend() | ||
|
||
# Display the figure in the div with id 'mpl' | ||
display(fig, target="mpl") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
name = "liteIndex benchmarks" | ||
packages = ["liteindex", "sqlite3", "diskcache", "matplotlib"] |
Oops, something went wrong.