Created
May 28, 2020 12:07
-
-
Save LIQRGV/d4668f882b3d7e55f59c682f5972c503 to your computer and use it in GitHub Desktop.
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
from random import choice | |
from time import time | |
def if_function(char_input): | |
if char_input == "A": | |
return "istimewa" | |
if char_input == "B": | |
return "baik" | |
if char_input == "C": | |
return "cukup" | |
else: | |
return "gagal" | |
def map_function_local(char_input): | |
local_map_nilai = { | |
'A': 'istimewa', | |
'B': 'baik', | |
'C': 'cukup', | |
'D': 'gagal', | |
} | |
return (local_map_nilai.get(char_input, 'gagal')) | |
global_map_nilai = { | |
'A': 'istimewa', | |
'B': 'baik', | |
'C': 'cukup', | |
'D': 'gagal', | |
} | |
def map_function_global(char_input): | |
return (global_map_nilai.get(char_input, 'gagal')) | |
def map_function_param(char_input, param_map_nilai): | |
return (param_map_nilai.get(char_input, 'gagal')) | |
options = ['A', 'B', 'C', 'D'] | |
loop_count = 100000 | |
start_if = time() | |
for i in range(0, loop_count): | |
char_input = choice(options) | |
if_function(char_input) | |
end_if = time() | |
start_map_local = time() | |
for i in range(0, loop_count): | |
char_input = choice(options) | |
map_function_local(char_input) | |
end_map_local = time() | |
start_map_global = time() | |
for i in range(0, loop_count): | |
char_input = choice(options) | |
map_function_global(char_input) | |
end_map_global = time() | |
start_map_param = time() | |
map_nilai = { | |
'A': 'istimewa', | |
'B': 'baik', | |
'C': 'cukup', | |
'D': 'gagal', | |
} | |
for i in range(0, loop_count): | |
char_input = choice(options) | |
map_function_param(char_input, map_nilai) | |
end_map_param = time() | |
print("IF: ", end_if - start_if) | |
print("MAP LOCAL: ", end_map_local - start_map_local) | |
print("MAP GLOBAL: ", end_map_global - start_map_global) | |
print("MAP PARAM: ", end_map_param - start_map_param) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment