Created
June 12, 2014 10:04
-
-
Save 24hours/33b76b4719ede2c13e44 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import sys, getopt | |
| def main(): | |
| try: | |
| opts, args = getopt.getopt(sys.argv[1:], "hm:t:", ["help", "memory=", "time="]) | |
| except getopt.GetoptError as err: | |
| # print help information and exit: | |
| print str(err) # will print something like "option -a not recognized" | |
| usage() | |
| sys.exit(2) | |
| mem_size = 100 | |
| exec_loop = 10 | |
| for o, a in opts: | |
| if o == "-v": | |
| verbose = True | |
| elif o in ("-h", "--help"): | |
| usage() | |
| sys.exit() | |
| elif o in ("-t", "--time"): | |
| exec_loop = int(a) | |
| elif o in ("-m", "--memory"): | |
| mem_size = int(a) | |
| else: | |
| assert False, "unhandled option" | |
| benchmark(mem_size, exec_loop) | |
| def benchmark(mem_size, exec_loop): | |
| mem = [0] * mem_size; | |
| for i in range(mem_size): | |
| mem[i] = [0]*mem_size | |
| mem_adjust = max(mem_size - exec_loop , 0) | |
| for i in range(exec_loop): | |
| for j in range(mem_adjust, mem_size): | |
| for k in range(mem_adjust, mem_size): | |
| mem[j][k] = (j*k)%256 | |
| return True | |
| def usage(): | |
| print "Benchmark Scirpt for nice and renice implementation on Python" | |
| print "Usage:" | |
| print " -m --memory memory to allocate for this benchmark default 100" | |
| print " -t --time time factor for this benchmark default 10" | |
| print " -m switch will only cause the script to occupy more memory with little impact on execution time, this assume that python have really good memory allocation mechanism" | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment