spacevim/bundle/deoplete-go/benchmark/benchmark.py
JIe 2bb7059579
Some checks failed
Detach Plugins / check (FlyGrep.vim) (push) Has been cancelled
Detach Plugins / check (GitHub.vim) (push) Has been cancelled
Detach Plugins / check (JavaUnit.vim) (push) Has been cancelled
Detach Plugins / check (SourceCounter.vim) (push) Has been cancelled
Detach Plugins / check (cpicker.nvim) (push) Has been cancelled
Detach Plugins / check (dein-ui.vim) (push) Has been cancelled
Detach Plugins / check (git.vim) (push) Has been cancelled
Detach Plugins / check (iedit.vim) (push) Has been cancelled
Detach Plugins / check (scrollbar.vim) (push) Has been cancelled
Detach Plugins / check (vim-chat) (push) Has been cancelled
Detach Plugins / check (vim-cheat) (push) Has been cancelled
Detach Plugins / check (vim-todo) (push) Has been cancelled
Detach Plugins / check (xmake.vim) (push) Has been cancelled
test / Linux (nvim, nightly) (push) Has been cancelled
test / Linux (nvim, v0.3.8) (push) Has been cancelled
test / Linux (nvim, v0.4.0) (push) Has been cancelled
test / Linux (nvim, v0.4.2) (push) Has been cancelled
test / Linux (nvim, v0.4.3) (push) Has been cancelled
test / Linux (nvim, v0.4.4) (push) Has been cancelled
test / Linux (nvim, v0.5.0) (push) Has been cancelled
test / Linux (nvim, v0.5.1) (push) Has been cancelled
test / Linux (nvim, v0.6.0) (push) Has been cancelled
test / Linux (nvim, v0.6.1) (push) Has been cancelled
test / Linux (nvim, v0.7.0) (push) Has been cancelled
test / Linux (nvim, v0.7.2) (push) Has been cancelled
test / Linux (nvim, v0.8.0) (push) Has been cancelled
test / Linux (nvim, v0.8.1) (push) Has been cancelled
test / Linux (nvim, v0.8.2) (push) Has been cancelled
test / Linux (nvim, v0.8.3) (push) Has been cancelled
test / Linux (nvim, v0.9.0) (push) Has been cancelled
test / Linux (nvim, v0.9.1) (push) Has been cancelled
test / Linux (true, vim, v7.4.052) (push) Has been cancelled
test / Linux (true, vim, v7.4.1689) (push) Has been cancelled
test / Linux (true, vim, v7.4.629) (push) Has been cancelled
test / Linux (true, vim, v8.0.0027) (push) Has been cancelled
test / Linux (true, vim, v8.0.0183) (push) Has been cancelled
test / Linux (vim, nightly) (push) Has been cancelled
test / Linux (vim, v8.0.0184) (push) Has been cancelled
test / Linux (vim, v8.0.1453) (push) Has been cancelled
test / Linux (vim, v8.1.2269) (push) Has been cancelled
test / Linux (vim, v8.2.2434) (push) Has been cancelled
test / Linux (vim, v8.2.3995) (push) Has been cancelled
test / Windows (nvim, nightly) (push) Has been cancelled
test / Windows (nvim, v0.3.8) (push) Has been cancelled
test / Windows (nvim, v0.4.2) (push) Has been cancelled
test / Windows (nvim, v0.4.3) (push) Has been cancelled
test / Windows (nvim, v0.4.4) (push) Has been cancelled
test / Windows (nvim, v0.5.0) (push) Has been cancelled
test / Windows (nvim, v0.5.1) (push) Has been cancelled
test / Windows (nvim, v0.6.0) (push) Has been cancelled
test / Windows (nvim, v0.6.1) (push) Has been cancelled
test / Windows (nvim, v0.7.0) (push) Has been cancelled
test / Windows (nvim, v0.7.2) (push) Has been cancelled
test / Windows (nvim, v0.8.0) (push) Has been cancelled
test / Windows (nvim, v0.8.1) (push) Has been cancelled
test / Windows (nvim, v0.8.2) (push) Has been cancelled
test / Windows (nvim, v0.8.3) (push) Has been cancelled
test / Windows (nvim, v0.9.0) (push) Has been cancelled
test / Windows (nvim, v0.9.1) (push) Has been cancelled
test / Windows (vim, nightly) (push) Has been cancelled
test / Windows (vim, v7.4.1185) (push) Has been cancelled
test / Windows (vim, v7.4.1689) (push) Has been cancelled
test / Windows (vim, v8.0.0027) (push) Has been cancelled
test / Windows (vim, v8.0.1453) (push) Has been cancelled
test / Windows (vim, v8.1.2269) (push) Has been cancelled
test / Windows (vim, v8.2.2434) (push) Has been cancelled
test / Windows (vim, v8.2.3995) (push) Has been cancelled
docker / docker (push) Has been cancelled
mirror / check (coding) (push) Has been cancelled
mirror / check (gitee) (push) Has been cancelled
mirror / check (gitlab) (push) Has been cancelled
init
2024-08-21 14:17:26 +08:00

99 lines
3.2 KiB
Python

from __future__ import print_function
import timeit
import importlib
import json
from collections import defaultdict
NUMBER = 100
def benchmark_loads(module, data):
module.loads(data)
def benchmark_dumps(module, obj):
module.dumps(obj)
def benchmark_loads_byline(module, lines):
for line in lines:
module.loads(line)
def benchmark_dumps_byline(module, lines):
for obj in lines:
module.dumps(obj)
def import_modules():
for name in ['json', 'simplejson', 'ujson', 'rapidjson']:
try:
yield importlib.import_module(name)
except ImportError:
print('Unable to import {}'.format(name))
continue
def print_results(results):
for suite_name, suite_results in results.items():
print(suite_name)
print('-' * 20)
for module_name, result in sorted(suite_results.items(), key=lambda x:x[1]):
print('{:10} {:.5f} s'.format(module_name, result))
print()
def run_benchmarks():
# filesize: 2248 byte
with open('json/fmt.json') as f:
fmt_objs_data = f.readlines()
fmt_objs = [json.loads(line) for line in fmt_objs_data]
# filesize: 116347 byte
with open('json/syscall.json') as f:
syscall_objs_data = f.readlines()
syscall_objs = [json.loads(line) for line in syscall_objs_data]
# filesize: 160808 byte
with open('json/gocode.json') as f:
gocode_objs_data = f.readlines()
gocode_objs = [json.loads(line) for line in gocode_objs_data]
# filesize: 1768818 byte
with open('json/gocode-twice.json') as f:
gocode_twice_objs_data = f.readlines()
gocode_twice_objs = [json.loads(line) for line in gocode_twice_objs_data]
results = defaultdict(dict)
modules = import_modules()
for module in modules:
module_name = module.__name__
print('Running {} benchmarks...'.format(module_name))
results['loads (fmt.json)'][module_name] = timeit.timeit(
lambda: benchmark_loads_byline(module, fmt_objs_data), number=NUMBER)
results['dumps (fmt.json)'][module_name] = timeit.timeit(
lambda: benchmark_dumps_byline(module, fmt_objs), number=NUMBER)
results['loads (syscall.json)'][module_name] = timeit.timeit(
lambda: benchmark_loads_byline(module, syscall_objs_data), number=NUMBER)
results['dumps (syscall.json)'][module_name] = timeit.timeit(
lambda: benchmark_dumps_byline(module, syscall_objs), number=NUMBER)
results['loads (gocode.json)'][module_name] = timeit.timeit(
lambda: benchmark_loads_byline(module, gocode_objs_data), number=NUMBER)
results['dumps (gocode.json)'][module_name] = timeit.timeit(
lambda: benchmark_dumps_byline(module, gocode_objs), number=NUMBER)
results['loads (gocode-twice.json)'][module_name] = timeit.timeit(
lambda: benchmark_loads_byline(module, gocode_twice_objs_data), number=NUMBER)
results['dumps (gocode-twice.json)'][module_name] = timeit.timeit(
lambda: benchmark_dumps_byline(module, gocode_twice_objs), number=NUMBER)
print('\nResults\n=======')
print_results(results)
if __name__ == '__main__':
run_benchmarks()