#!/usr/bin/env python3
# -*- coding: UTF-8 -*-

import time
import os
import uuid

RepeatTime=int(input("Repeat Time:")) #重复几次测试
testNum=int(input("Test Num:")) #每次测试程序数量
testTime=int(input("Test Time:")) #每次测试每个程序测试重复次数
gen=input("Gen Command:") #数据生成器
path=input("Path:") #工作目录
gen_same_input=int(input("Gen same input? 1 for Yes or 0 for no:"))
if(gen_same_input):
    gen_input=input("Gen input:")
os.chdir(path) #进入工作目录

pro=[] #程序
timeUsed=[]
timeSum=[]

for i in range(testNum):
    prog=input("Program " + str(i) + " Command:")
    pro.append(prog)

TestUUID=str(uuid.uuid5(uuid.NAMESPACE_URL,"github.com/cms42/OI-share/27ecd194-b044-11e9-b812-00e04c1e08c7-pipe-b3log-org-1564214175618/test.py"+str(uuid.uuid1())))

os.system("mkdir -p ./"+TestUUID)
os.chdir(TestUUID)

for i in range(RepeatTime):
    os.system("mkdir -p test"+str(i))
    os.chdir("test"+str(i))
    print("Generating data",i)
    if(gen_same_input):
        os.system("../../"+gen+" < ../../"+gen_input+" > input")
    else:
        os.system("../../"+gen+" > input")
    TMP=[]
    for j in range(testNum):
        print("Testing program",j)
        if(i==0):
            timeSum.append(0.0)
        thisSum=0
        for k in range(testTime):
            print("Testing program",j,", round",k)
            start=time.time() #注意这里一定要用time()不能用clock()！一定不能！
            os.system("../../"+pro[j])
            end=time.time()
            usedTime=end-start
            os.system("mv output output-pro"+str(j)+"-test"+str(k))
            print("Finished program",j,",round",k,"Time used:",usedTime)
            thisSum+=usedTime
        t1=thisSum/testTime
        print("Finished program",j," Avg.Time used:",t1)
        TMP.append(thisSum/testTime)
        timeSum[j]+=thisSum/testTime
    timeUsed.append(TMP)
    os.chdir("../")

print("\n")
print(str(timeUsed))
print("\n")
print(str(timeSum))

print("Done")
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-

import time
import os
import uuid

RepeatTime=int(input("Repeat Time:")) #重复几次测试
testNum=int(input("Test Num:")) #每次测试程序数量
testTime=int(input("Test Time:")) #每次测试每个程序测试重复次数
gen=input("Gen Command:") #数据生成器
path=input("Path:") #工作目录
gen_same_input=int(input("Gen same input? 1 for Yes or 0 for no:"))
if(gen_same_input):
    gen_input=input("Gen input:")
os.chdir(path) #进入工作目录

pro=[] #程序
timeUsed=[]
timeSum=[]

for i in range(testNum):
    prog=input("Program " + str(i) + " Command:")
    pro.append(prog)

TestUUID=str(uuid.uuid5(uuid.NAMESPACE_URL,"github.com/cms42/OI-share/27ecd194-b044-11e9-b812-00e04c1e08c7-pipe-b3log-org-1564214175618/test.py"+str(uuid.uuid1())))

os.system("mkdir -p ./"+TestUUID)
os.chdir(TestUUID)

for i in range(RepeatTime):
    os.system("mkdir -p test"+str(i))
    os.chdir("test"+str(i))
    print("Generating data",i)
    if(gen_same_input):
        os.system("../../"+gen+" < ../../"+gen_input+" > input")
    else:
        os.system("../../"+gen+" > input")
    TMP=[]
    for j in range(testNum):
        print("Testing program",j)
        if(i==0):
            timeSum.append(0.0)
        thisSum=0
        for k in range(testTime):
            print("Testing program",j,", round",k)
            start=time.time() #注意这里一定要用time()不能用clock()！一定不能！
            os.system("../../"+pro[j])
            end=time.time()
            usedTime=end-start
            os.system("mv output output-pro"+str(j)+"-test"+str(k))
            print("Finished program",j,",round",k,"Time used:",usedTime)
            thisSum+=usedTime
        t1=thisSum/testTime
        print("Finished program",j," Avg.Time used:",t1)
        TMP.append(thisSum/testTime)
        timeSum[j]+=thisSum/testTime
    timeUsed.append(TMP)
    os.chdir("../")

print("\n")
print(str(timeUsed))
print("\n")
print(str(timeSum))

print("Done")
#!/usr/bin/env python3 # -*- coding: UTF-8 -*- #重复几次测试 #每次测试程序数量 #每次测试每个程序测试重复次数 #数据生成器 #工作目录 #进入工作目录 #程序 #注意这里一定要用time()不能用clock()！一定不能！