Created
August 4, 2022 06:43
-
-
Save c-bata/53f3b6a9d9e28afa4fb50007594b856a to your computer and use it in GitHub Desktop.
Benchmark scripts for https://github.com/optuna/optuna-dashboard/compare/main...c-bata:optuna-dashboard:incremental-tirals-update?expand=1
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
import time | |
import numpy | |
from bottle import Bottle | |
from optuna_dashboard import wsgi | |
from optuna.storages import RDBStorage | |
from python_tests.wsgi_client import send_request | |
# Before: | |
# $ python benchmark.py | |
# mean=0.019s std=0.016 | |
# | |
# After: | |
# $ python benchmark.py | |
# mean=0.019s std=0.016 | |
def main(): | |
storage = RDBStorage("sqlite:///db2.sqlite3") | |
app = wsgi(storage) | |
assert isinstance(app, Bottle) | |
study_id = 1 | |
# Get trials?after=500 | |
elapsed = [] | |
for _ in range(100): | |
start = time.time() | |
status, _, body = send_request( | |
app, | |
f"/api/studies/{study_id}", | |
"GET", | |
queries={"after": "500"}, | |
content_type="application/json", | |
) | |
assert 200 <= status < 300 | |
elapsed.append(time.time() - start) | |
print(f"mean={numpy.mean(elapsed):.3f}s std={numpy.std(elapsed):.3f}") | |
if __name__ == '__main__': | |
main() | |
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
import optuna | |
optuna.logging.set_verbosity(optuna.logging.ERROR) | |
def main(): | |
study = optuna.create_study( | |
sampler=optuna.samplers.RandomSampler(), | |
study_name="20000trials-part2", | |
storage="sqlite:///db2.sqlite3", | |
load_if_exists=True | |
) | |
study.optimize(lambda t: t.suggest_float("x", 0, 1), n_trials=20 * 1000) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
追加でMySQLでの確認が必要
早くなっていない理由として考えられるところ
WHERE trials.number > hoge
で取ってくる参考資料: https://www.slideshare.net/c-bata/django-rest-framework-api-pycon-jp-2018-114941317