Added count_lens for get_function_len
This commit is contained in:
@@ -10,8 +10,8 @@ def get_rank_file_object(args_count, rank_ind):
|
|||||||
elif os.path.exists(base_name + ".xz"):
|
elif os.path.exists(base_name + ".xz"):
|
||||||
return lzma.open(base_name + ".xz", 'rb')
|
return lzma.open(base_name + ".xz", 'rb')
|
||||||
else:
|
else:
|
||||||
print("No results file for {} arguments rank {}".format(args_count, rank_ind))
|
return None
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
def is_function_exists(function_number, file_object):
|
def is_function_exists(function_number, file_object):
|
||||||
file_object.seek(function_number // 8)
|
file_object.seek(function_number // 8)
|
||||||
@@ -29,7 +29,29 @@ def function_values_to_number(values):
|
|||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
def count_lens(args_count):
|
||||||
|
bit_counts = bytes(bin(x).count("1") for x in range(256))
|
||||||
|
len_to_count = {}
|
||||||
|
for rank_ind in range(1, 10):
|
||||||
|
file_object = get_rank_file_object(args_count, rank_ind)
|
||||||
|
if not file_object:
|
||||||
|
break
|
||||||
|
len_to_count[rank_ind] = sum(map(lambda x: bit_counts[x], file_object.read()))
|
||||||
|
total = sum(len_to_count.values())
|
||||||
|
for rank_ind, count in len_to_count.items():
|
||||||
|
print("len {} count {} share {}".format(
|
||||||
|
rank_ind,
|
||||||
|
count,
|
||||||
|
1. * count / total
|
||||||
|
))
|
||||||
|
print("average: {}".format(
|
||||||
|
sum([key*value for key,value in len_to_count.items()]) / total
|
||||||
|
))
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
if sys.argv[1] == "count_lens":
|
||||||
|
count_lens(sys.argv[2])
|
||||||
|
return
|
||||||
args_count = {
|
args_count = {
|
||||||
8: 3,
|
8: 3,
|
||||||
16: 4,
|
16: 4,
|
||||||
@@ -38,7 +60,11 @@ def main():
|
|||||||
function_number = function_values_to_number(sys.argv[1])
|
function_number = function_values_to_number(sys.argv[1])
|
||||||
print("Function number is {}".format(function_number))
|
print("Function number is {}".format(function_number))
|
||||||
for rank_ind in range(1, 10):
|
for rank_ind in range(1, 10):
|
||||||
if is_function_exists(function_number, get_rank_file_object(args_count, rank_ind)):
|
file_object = get_rank_file_object(args_count, rank_ind)
|
||||||
|
if not file_object:
|
||||||
|
print("No results file for {} arguments rank {}".format(args_count, rank_ind))
|
||||||
|
sys.exit(1)
|
||||||
|
if is_function_exists(function_number, file_object):
|
||||||
print("Result len is {}".format(rank_ind))
|
print("Result len is {}".format(rank_ind))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user