summary refs log blame commit diff stats
path: root/test/dirsize_benchmark.py
blob: 5784ee805e9c653cc3869a799f62c67beb169c25 (plain) (tree)

























                                                                                 

      
import os, time
class Dirsize():
	def a(path):
		return len(os.listdir(path))

	def b(path):
		for _, dirs, files in os.walk(path):
			return len(files) + len(dirs)

	def c(path):
		first = next(os.walk(path))
		return len(first[1]) + len(first[2])

paths = {
		'/usr/lib': None,
		'/usr/bin': None,
		'/home/hut': None
}

for key in paths.keys():
	paths[key] = Dirsize.a(key) # assume Dirsize.a() returns a correct result
	for algo in ['a', 'b', 'c']:
		t = time.time()
		for i in range(4):
			assert Dirsize.__dict__[algo](key) == paths[key]
		print("algorithm %s: %20s: %f" % (algo, key, time.time() - t))

# a !!
alt'>
                         


            
# example program: compute the factorial of 5

def main [
  local-scope
  x:num <- factorial 5
  $print [result: ], x, [ 
]
]

def factorial n:num -> result:num [
  local-scope
  load-inputs
  {
    # if n=0 return 1
    zero?:bool <- equal n, 0
    break-unless zero?
    return 1
  }
  # return n * factorial(n-1)
  x:num <- subtract n, 1
  subresult:num <- factorial x
  result <- multiply subresult, n
]

# unit test
scenario factorial-test [
  run [
    1:num <- factorial 5
  ]
  memory-should-contain [
    1 <- 120
  ]
]