TF cardの読み書き速度をテストする

2456 ワード

TF cardの読み書き速度

# _*_ coding: utf_8 _*_

import time
import datetime

def test_card_r():
    fin = open('test1.txt')
    for line in fin:
        word = line.strip()
    return word


def test_card_w(num):
    test1 = open('test1.txt', 'w')
    while True:
        line = "Holle world"
        test1.write(line)
        length = test1.tell()
        if length >= (1024 ** 2 * num):
            print length
            break
    return test1

def datetime_now():
    now = int(time.time())
    print('now:' , now)
    return now

def card_time(num):
    w_start_time = datetime_now()
    test_card_w(num)
    r_start_time = datetime_now()
    test_card_r()
    time = datetime_now()
    w_time = r_start_time - w_start_time
    print('w_time:', w_time)
    wv = num / float(w_time)
    print('wv:' , wv)
    r_time = time - r_start_time
    print r_time
    f_time = time - w_start_time
    print f_time
    return f_time

card_time(50)