找回密码
 注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

  • QQ空间
  • 回复
  • 收藏

© nastro 新手上路   /  2018-10-15 14:30  /   0 人收藏

本帖最后由 nastro 于 2018-10-15 15:05 编辑

#-------------------------------------------
#   Nastro P.
#   nas_patt@protonmail.com
#   10/15/2018 GMT+8 11:49
#   ver 0.0.1
#   Any contribution to this script is welcomed.
#
#   Open-sourced under GPL v3.0 License
#   https://www.gnu.org/licenses/gpl-3.0.html
#  
#-------------------------------------------

import random
import time
from os import system
import sys

def main():
    sh_flush="sudo su"
    # Get permission to create and delete files
    randfile=open("/dev/urandom","rb")
    # Use urandom to get a random numer
    print("[+]Creating Test Folder")
    starttime=time.time()
    system("rm -rf test && mkdir test")
    print("[+]Time Spent: %.3f"%float(time.time()-starttime))
    print("[+]Write-in Test")
    starttime=time.time()
    for i in range(0,filesize):
        rand=randfile.read(int(filesize*0.5+filesize*random.random()))
        outfile=open("test/"+str(i),"w")
        outfile.write(str(rand))
    writetime=float(time.time()-starttime)
    print("[+]Writing ",filesize," File(s) Costs %.3f"%writetime)
    print("[+]Linear reading test")
    outfile=open("test/output","w")
    for i in range(0,filecount):
        outfile.write(str(randfile.read(int(random.random()))))
    outfile.close()
    starttime=time.time()
    readfile=open("test/output","r")
    lines=readfile.readlines()
    readtime=float(time.time()-starttime)
    print("[+]Time cost: %.3f"%float(time.time()-starttime)," reading ",filecount, "lines")
    print("Deleting all testing files:")
    starttime=time.time()
    system("rm -rf test")
    print("[+]Time cost: %.3f\n"%float(time.time()-starttime))
    scorelist.append(int((filecount/readtime+filesize/writetime)/100))
   
if __name__=='__main__':
    #------------------------|
    filecount=65536         #|
    filesize=1024           #|  
    testcount=100           #|
    #------------------------|
    # These three arguments are allowed to change
    ExFileOut=False
    OutputTerminal=sys.stdout
    if len(sys.argv)>=2:
        ExFileOut=True
        if(sys.argv[1]=="test"):
            print("[-]Test data file cannot be named as 'text'! Try another name.")
            print("[-]Aborting...")
            sys.exit(3)
        TestOutputFile=open(sys.argv[1],"w");
        sys.stdout=TestOutputFile
    sumscore=0
    scorelist=[]
    # Platform choose,by now only Linux is supported.
    if 'linux' not in sys.platform:
        print("[-]The system platform is not supported!")
        print("[-]Aborting... ")
        sys.exit(3)
    # Start testing
    for i in range(0,testcount):
        print("Test round ",i+1)
        main()
    for i in scorelist:
        sumscore+=i
    print("#----------SCORE----------#")
    print(int(sumscore/len(scorelist)))
    if(ExFileOut==True):
        TestOutputFile.close();
        sys.stdout=OutputTerminal
        print("#----------SCORE----------#")
        print(int(sumscore/len(scorelist)))
        print("The Detailed testing data has been save in file: ./",sys.argv[1])
发表评论
您需要登录后才可以回帖 登录 | 注册