2018-04-10 20:26:17 +00:00
|
|
|
# This import depends on the automake rule protoc_middleman, please make sure
|
|
|
|
# protoc_middleman has been built before run this file.
|
2018-07-18 20:45:32 +00:00
|
|
|
import json
|
|
|
|
import re
|
|
|
|
import os.path
|
|
|
|
# BEGIN OPENSOURCE
|
|
|
|
import sys
|
2018-04-10 20:26:17 +00:00
|
|
|
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir))
|
2018-07-18 20:45:32 +00:00
|
|
|
# END OPENSOURCE
|
2018-04-10 20:26:17 +00:00
|
|
|
import tmp.benchmarks_pb2 as benchmarks_pb2
|
|
|
|
|
2018-07-18 20:45:32 +00:00
|
|
|
__file_size_map = {}
|
2018-04-10 20:26:17 +00:00
|
|
|
|
2018-07-18 20:45:32 +00:00
|
|
|
def __get_data_size(filename):
|
|
|
|
if filename[0] != '/':
|
|
|
|
filename = os.path.dirname(os.path.abspath(__file__)) + "/../" + filename
|
|
|
|
if filename in __file_size_map:
|
|
|
|
return __file_size_map[filename]
|
2018-04-10 20:26:17 +00:00
|
|
|
benchmark_dataset = benchmarks_pb2.BenchmarkDataset()
|
|
|
|
benchmark_dataset.ParseFromString(
|
2018-07-18 20:45:32 +00:00
|
|
|
open(filename).read())
|
2018-04-10 20:26:17 +00:00
|
|
|
size = 0
|
|
|
|
count = 0
|
|
|
|
for payload in benchmark_dataset.payload:
|
|
|
|
size += len(payload)
|
|
|
|
count += 1
|
2018-07-18 20:45:32 +00:00
|
|
|
__file_size_map[filename] = (size, 1.0 * size / count)
|
2018-04-10 20:26:17 +00:00
|
|
|
return size, 1.0 * size / count
|
|
|
|
|
|
|
|
|
2018-07-18 20:45:32 +00:00
|
|
|
def __extract_file_name(file_name):
|
2018-04-10 20:26:17 +00:00
|
|
|
name_list = re.split("[/\.]", file_name)
|
|
|
|
short_file_name = ""
|
|
|
|
for name in name_list:
|
|
|
|
if name[:14] == "google_message":
|
|
|
|
short_file_name = name
|
|
|
|
return short_file_name
|
|
|
|
|
|
|
|
|
2018-07-18 20:45:32 +00:00
|
|
|
__results = []
|
2018-04-10 20:26:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
# CPP results example:
|
2018-07-18 20:45:32 +00:00
|
|
|
# [
|
|
|
|
# "benchmarks": [
|
2018-04-10 20:26:17 +00:00
|
|
|
# {
|
|
|
|
# "bytes_per_second": int,
|
2018-09-04 17:58:54 +00:00
|
|
|
# "cpu_time_ns": double,
|
|
|
|
# "iterations": int,
|
2018-04-10 20:26:17 +00:00
|
|
|
# "name: string,
|
2018-09-04 17:58:54 +00:00
|
|
|
# "real_time_ns: double,
|
2018-04-10 20:26:17 +00:00
|
|
|
# ...
|
|
|
|
# },
|
2018-07-18 20:45:32 +00:00
|
|
|
# ...
|
2018-04-10 20:26:17 +00:00
|
|
|
# ],
|
2018-07-18 20:45:32 +00:00
|
|
|
# ...
|
2018-04-10 20:26:17 +00:00
|
|
|
# ]
|
2018-07-18 20:45:32 +00:00
|
|
|
def __parse_cpp_result(filename):
|
2018-04-10 20:26:17 +00:00
|
|
|
if filename == "":
|
|
|
|
return
|
|
|
|
if filename[0] != '/':
|
|
|
|
filename = os.path.dirname(os.path.abspath(__file__)) + '/' + filename
|
|
|
|
with open(filename) as f:
|
|
|
|
results = json.loads(f.read())
|
|
|
|
for benchmark in results["benchmarks"]:
|
|
|
|
data_filename = "".join(
|
|
|
|
re.split("(_parse_|_serialize)", benchmark["name"])[0])
|
|
|
|
behavior = benchmark["name"][len(data_filename) + 1:]
|
2018-07-18 20:45:32 +00:00
|
|
|
if data_filename[:2] == "BM":
|
|
|
|
data_filename = data_filename[3:]
|
|
|
|
__results.append({
|
2018-04-10 20:26:17 +00:00
|
|
|
"language": "cpp",
|
2018-07-18 20:45:32 +00:00
|
|
|
"dataFilename": data_filename,
|
2018-04-10 20:26:17 +00:00
|
|
|
"behavior": behavior,
|
|
|
|
"throughput": benchmark["bytes_per_second"] / 2.0 ** 20
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2018-09-04 17:58:54 +00:00
|
|
|
# Synthetic benchmark results example:
|
|
|
|
# [
|
|
|
|
# "benchmarks": [
|
|
|
|
# {
|
|
|
|
# "cpu_time_ns": double,
|
|
|
|
# "iterations": int,
|
|
|
|
# "name: string,
|
|
|
|
# "real_time_ns: double,
|
|
|
|
# ...
|
|
|
|
# },
|
|
|
|
# ...
|
|
|
|
# ],
|
|
|
|
# ...
|
|
|
|
# ]
|
|
|
|
def __parse_synthetic_result(filename):
|
|
|
|
if filename == "":
|
|
|
|
return
|
|
|
|
if filename[0] != "/":
|
|
|
|
filename = os.path.dirname(os.path.abspath(__file__)) + "/" + filename
|
|
|
|
with open(filename) as f:
|
|
|
|
results = json.loads(f.read())
|
|
|
|
for benchmark in results["benchmarks"]:
|
|
|
|
__results.append({
|
|
|
|
"language": "cpp",
|
|
|
|
"dataFilename": "",
|
|
|
|
"behavior": "synthetic",
|
|
|
|
"throughput": 10.0**9 / benchmark["cpu_time_ns"]
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2018-04-10 20:26:17 +00:00
|
|
|
# Python results example:
|
2018-07-18 20:45:32 +00:00
|
|
|
# [
|
|
|
|
# [
|
2018-04-10 20:26:17 +00:00
|
|
|
# {
|
|
|
|
# "filename": string,
|
|
|
|
# "benchmarks": {
|
2018-07-18 20:45:32 +00:00
|
|
|
# behavior: results,
|
2018-04-10 20:26:17 +00:00
|
|
|
# ...
|
|
|
|
# },
|
|
|
|
# },
|
2018-07-18 20:45:32 +00:00
|
|
|
# ...
|
2018-04-10 20:26:17 +00:00
|
|
|
# ], #pure-python
|
2018-07-18 20:45:32 +00:00
|
|
|
# ...
|
2018-04-10 20:26:17 +00:00
|
|
|
# ]
|
2018-07-18 20:45:32 +00:00
|
|
|
def __parse_python_result(filename):
|
2018-04-10 20:26:17 +00:00
|
|
|
if filename == "":
|
|
|
|
return
|
|
|
|
if filename[0] != '/':
|
|
|
|
filename = os.path.dirname(os.path.abspath(__file__)) + '/' + filename
|
|
|
|
with open(filename) as f:
|
|
|
|
results_list = json.loads(f.read())
|
|
|
|
for results in results_list:
|
|
|
|
for result in results:
|
2018-07-18 20:45:32 +00:00
|
|
|
_, avg_size = __get_data_size(result["filename"])
|
2018-04-10 20:26:17 +00:00
|
|
|
for behavior in result["benchmarks"]:
|
2018-07-18 20:45:32 +00:00
|
|
|
__results.append({
|
2018-04-10 20:26:17 +00:00
|
|
|
"language": "python",
|
2018-07-18 20:45:32 +00:00
|
|
|
"dataFilename": __extract_file_name(result["filename"]),
|
2018-04-10 20:26:17 +00:00
|
|
|
"behavior": behavior,
|
2018-09-25 23:05:16 +00:00
|
|
|
"throughput": result["benchmarks"][behavior]
|
2018-04-10 20:26:17 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
# Java results example:
|
2018-07-18 20:45:32 +00:00
|
|
|
# [
|
2018-04-10 20:26:17 +00:00
|
|
|
# {
|
|
|
|
# "id": string,
|
|
|
|
# "instrumentSpec": {...},
|
|
|
|
# "measurements": [
|
|
|
|
# {
|
|
|
|
# "weight": float,
|
|
|
|
# "value": {
|
|
|
|
# "magnitude": float,
|
|
|
|
# "unit": string
|
|
|
|
# },
|
|
|
|
# ...
|
|
|
|
# },
|
|
|
|
# ...
|
|
|
|
# ],
|
|
|
|
# "run": {...},
|
|
|
|
# "scenario": {
|
|
|
|
# "benchmarkSpec": {
|
|
|
|
# "methodName": string,
|
|
|
|
# "parameters": {
|
|
|
|
# defined parameters in the benchmark: parameters value
|
|
|
|
# },
|
|
|
|
# ...
|
|
|
|
# },
|
|
|
|
# ...
|
|
|
|
# }
|
2018-07-18 20:45:32 +00:00
|
|
|
#
|
|
|
|
# },
|
|
|
|
# ...
|
2018-04-10 20:26:17 +00:00
|
|
|
# ]
|
2018-07-18 20:45:32 +00:00
|
|
|
def __parse_java_result(filename):
|
2018-04-10 20:26:17 +00:00
|
|
|
if filename == "":
|
|
|
|
return
|
|
|
|
if filename[0] != '/':
|
|
|
|
filename = os.path.dirname(os.path.abspath(__file__)) + '/' + filename
|
|
|
|
with open(filename) as f:
|
|
|
|
results = json.loads(f.read())
|
|
|
|
for result in results:
|
|
|
|
total_weight = 0
|
|
|
|
total_value = 0
|
|
|
|
for measurement in result["measurements"]:
|
|
|
|
total_weight += measurement["weight"]
|
|
|
|
total_value += measurement["value"]["magnitude"]
|
|
|
|
avg_time = total_value * 1.0 / total_weight
|
2018-07-18 20:45:32 +00:00
|
|
|
total_size, _ = __get_data_size(
|
2018-04-10 20:26:17 +00:00
|
|
|
result["scenario"]["benchmarkSpec"]["parameters"]["dataFile"])
|
2018-07-18 20:45:32 +00:00
|
|
|
__results.append({
|
2018-04-10 20:26:17 +00:00
|
|
|
"language": "java",
|
|
|
|
"throughput": total_size / avg_time * 1e9 / 2 ** 20,
|
|
|
|
"behavior": result["scenario"]["benchmarkSpec"]["methodName"],
|
2018-07-18 20:45:32 +00:00
|
|
|
"dataFilename": __extract_file_name(
|
2018-04-10 20:26:17 +00:00
|
|
|
result["scenario"]["benchmarkSpec"]["parameters"]["dataFile"])
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
# Go benchmark results:
|
|
|
|
#
|
|
|
|
# goos: linux
|
|
|
|
# goarch: amd64
|
|
|
|
# Benchmark/.././datasets/google_message2/dataset.google_message2.pb/Unmarshal-12 3000 705784 ns/op
|
|
|
|
# Benchmark/.././datasets/google_message2/dataset.google_message2.pb/Marshal-12 2000 634648 ns/op
|
|
|
|
# Benchmark/.././datasets/google_message2/dataset.google_message2.pb/Size-12 5000 244174 ns/op
|
|
|
|
# Benchmark/.././datasets/google_message2/dataset.google_message2.pb/Clone-12 300 4120954 ns/op
|
|
|
|
# Benchmark/.././datasets/google_message2/dataset.google_message2.pb/Merge-12 300 4108632 ns/op
|
|
|
|
# PASS
|
|
|
|
# ok _/usr/local/google/home/yilunchong/mygit/protobuf/benchmarks 124.173s
|
2018-07-18 20:45:32 +00:00
|
|
|
def __parse_go_result(filename):
|
2018-04-10 20:26:17 +00:00
|
|
|
if filename == "":
|
|
|
|
return
|
|
|
|
if filename[0] != '/':
|
|
|
|
filename = os.path.dirname(os.path.abspath(__file__)) + '/' + filename
|
|
|
|
with open(filename) as f:
|
|
|
|
for line in f:
|
|
|
|
result_list = re.split("[\ \t]+", line)
|
|
|
|
if result_list[0][:9] != "Benchmark":
|
|
|
|
continue
|
|
|
|
first_slash_index = result_list[0].find('/')
|
|
|
|
last_slash_index = result_list[0].rfind('/')
|
2018-09-25 23:05:16 +00:00
|
|
|
full_filename = result_list[0][first_slash_index+1:last_slash_index]
|
2018-07-18 20:45:32 +00:00
|
|
|
total_bytes, _ = __get_data_size(full_filename)
|
2018-04-10 20:26:17 +00:00
|
|
|
behavior_with_suffix = result_list[0][last_slash_index+1:]
|
|
|
|
last_dash = behavior_with_suffix.rfind("-")
|
|
|
|
if last_dash == -1:
|
|
|
|
behavior = behavior_with_suffix
|
|
|
|
else:
|
|
|
|
behavior = behavior_with_suffix[:last_dash]
|
2018-07-18 20:45:32 +00:00
|
|
|
__results.append({
|
|
|
|
"dataFilename": __extract_file_name(full_filename),
|
2018-04-10 20:26:17 +00:00
|
|
|
"throughput": total_bytes / float(result_list[2]) * 1e9 / 2 ** 20,
|
|
|
|
"behavior": behavior,
|
|
|
|
"language": "go"
|
|
|
|
})
|
|
|
|
|
2018-09-04 17:58:54 +00:00
|
|
|
|
2018-10-16 00:25:02 +00:00
|
|
|
# Self built json results example:
|
2018-09-25 23:05:16 +00:00
|
|
|
#
|
|
|
|
# [
|
|
|
|
# {
|
|
|
|
# "filename": string,
|
|
|
|
# "benchmarks": {
|
|
|
|
# behavior: results,
|
|
|
|
# ...
|
|
|
|
# },
|
|
|
|
# },
|
|
|
|
# ...
|
|
|
|
# ]
|
2018-10-16 00:25:02 +00:00
|
|
|
def __parse_custom_result(filename, language):
|
2018-09-25 23:05:16 +00:00
|
|
|
if filename == "":
|
|
|
|
return
|
|
|
|
if filename[0] != '/':
|
|
|
|
filename = os.path.dirname(os.path.abspath(__file__)) + '/' + filename
|
|
|
|
with open(filename) as f:
|
|
|
|
results = json.loads(f.read())
|
|
|
|
for result in results:
|
|
|
|
_, avg_size = __get_data_size(result["filename"])
|
|
|
|
for behavior in result["benchmarks"]:
|
|
|
|
__results.append({
|
|
|
|
"language": language,
|
|
|
|
"dataFilename": __extract_file_name(result["filename"]),
|
|
|
|
"behavior": behavior,
|
|
|
|
"throughput": result["benchmarks"][behavior]
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2018-10-13 01:17:23 +00:00
|
|
|
def __parse_js_result(filename, language):
|
2018-10-16 00:25:02 +00:00
|
|
|
return __parse_custom_result(filename, language)
|
2018-10-13 01:17:23 +00:00
|
|
|
|
|
|
|
def __parse_php_result(filename, language):
|
2018-10-16 00:25:02 +00:00
|
|
|
return __parse_custom_result(filename, language)
|
2018-10-13 01:17:23 +00:00
|
|
|
|
2018-09-25 23:05:16 +00:00
|
|
|
|
2018-09-04 17:58:54 +00:00
|
|
|
def get_result_from_file(cpp_file="",
|
|
|
|
java_file="",
|
|
|
|
python_file="",
|
|
|
|
go_file="",
|
2018-09-25 23:05:16 +00:00
|
|
|
synthetic_file="",
|
|
|
|
node_file="",
|
|
|
|
php_c_file="",
|
|
|
|
php_file=""):
|
2018-07-18 20:45:32 +00:00
|
|
|
results = {}
|
|
|
|
if cpp_file != "":
|
|
|
|
__parse_cpp_result(cpp_file)
|
|
|
|
if java_file != "":
|
|
|
|
__parse_java_result(java_file)
|
|
|
|
if python_file != "":
|
|
|
|
__parse_python_result(python_file)
|
|
|
|
if go_file != "":
|
|
|
|
__parse_go_result(go_file)
|
2018-09-04 17:58:54 +00:00
|
|
|
if synthetic_file != "":
|
|
|
|
__parse_synthetic_result(synthetic_file)
|
2018-09-25 23:05:16 +00:00
|
|
|
if node_file != "":
|
2018-10-13 01:17:23 +00:00
|
|
|
__parse_js_result(node_file, "node")
|
2018-09-25 23:05:16 +00:00
|
|
|
if php_file != "":
|
2018-10-13 01:17:23 +00:00
|
|
|
__parse_php_result(php_file, "php")
|
2018-09-25 23:05:16 +00:00
|
|
|
if php_c_file != "":
|
2019-02-21 03:28:50 +00:00
|
|
|
__parse_php_result(php_c_file, "php")
|
2018-07-18 20:45:32 +00:00
|
|
|
|
2018-09-04 17:58:54 +00:00
|
|
|
return __results
|