Created
June 14, 2022 22:37
-
-
Save FindHao/81d1283a7428838a77063a889f0ec0c0 to your computer and use it in GitHub Desktop.
convert linux time cmd's results
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
def time_convert(tmp_str): | |
""" | |
convert linux time cmd's results to seconds. | |
""" | |
tmp_str = tmp_str.strip() | |
result = [ _ for _ in re.split('[ms]', tmp_str) if _.strip()] | |
if len(result) != 2: | |
print("error when convert time ", tmp_str) | |
return None | |
return float(result[0]) * 60 + float(result[1]) | |
def get_mean_time_cmd(reg, content): | |
results = reg.findall(content) | |
if not results: | |
reg2 = re.compile(r"@Yueming Hao: Run (.*)") | |
print("error for ", reg2.findall(content)[0]) | |
return None | |
results = [ time_convert(_) for _ in results[0] ] | |
print(results) | |
return np.mean(results) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment