#!/usr/bin/env python

__author__ = 'setten'

import timeit
import os


def test_write():
    """file write test function"""
    l = []
    for i in range(100000):
        l.append(i)
    f = open('test', 'w')
    f.write(str(l))
    f.close()


def test_read():
    f = open('test', mode='r')
    line = f.read()
    f.close()


def test_make_folders():
    for i in range(0, 100, 1):
        os.mkdir('test_folder_%s' % i)
        os.rmdir('test_folder_%s' % i)


def test_cd():
    for i in range(0, 100, 1):
        os.mkdir('test_folder_%s' % i)
        os.chdir('test_folder_%s' % i)
        os.chdir('..')
        os.rmdir('test_folder_%s' % i)


if __name__ == '__main__':
    n = 100
    print 'write', timeit.timeit("test_write()", setup="from __main__ import test_write", number=n)
    print 'read (200 times as many)', timeit.timeit("test_read()", setup="from __main__ import test_read", number=n*200)
    print 'mk folders', timeit.timeit("test_make_folders()", setup="from __main__ import test_make_folders", number=n)
    print 'cd folders', timeit.timeit("test_cd()", setup="from __main__ import test_cd", number=n)

    assert timeit.timeit("test_write()", setup="from __main__ import test_write", number=n) < 5
    assert timeit.timeit("test_read()", setup="from __main__ import test_read", number=n*200) < 5
    assert timeit.timeit("test_make_folders()", setup="from __main__ import test_make_folders", number=n) < 1
    assert timeit.timeit("test_cd()", setup="from __main__ import test_cd", number=n) < 1

@@ -690,26 +690,101 @@
 100%0A
-    print '
+%0A    test_write()%0A    size = os.path.getsize('test')%0A    print 'file size', size%0A%0A    
 write
-',
+ =
  tim
@@ -869,41 +869,14 @@
     
-print 'read (200 times as many)',
+read =
  tim
@@ -963,27 +963,20 @@
     
-print '
 mk
- 
+_
 folders
-',
+ =
  tim
@@ -1075,27 +1075,20 @@
     
-print '
 cd
- 
+_
 folders
-',
+ =
  tim
@@ -1168,393 +1168,364 @@
     
-assert timeit.timeit(%22test_write()%22, setup=%22from __main__ import test_
+print n, 'times written: ', write, ', ', size * n / 
 write
-%22
 , 
-number=n) %3C 5%0A    assert timeit.timeit(%22test_read()%22, setup=%22from __main__ import test_
+'b/s'%0A    print n*200, 'times read:  ', 
 read
-%22
 , 
-number=n*200) %3C 5%0A    assert timeit.timeit(%22test_make_folders()%22, setup=%22from __main__ import test_make_
+', ', size * 200 * n / write, 'b/s'%0A    print 'made and removed 100 folders', mk_folders%0A    print 'made, moved to, returned and removed 100 
 folders
-%22, number=n) %3C 1%0A    assert timeit.timeit(%22test_cd()%22, setup=%22from __main__ import test_cd%22, number=n)
+', cd_folders%0A%0A    assert write %3C 5%0A    assert read %3C 5%0A    assert mk_folders %3C 1%0A    assert cd_folders
  %3C 1

test times