Beispiel #1
0
#!/usr/local/bin/python3

# This file was created on 12/05/2016
# Author: George Kaimakis
# This code from 'Generator tutorial' by Corey Schafer (https://www.coreyms.com)

import mem_profile
import random
import time

names = ['John', 'Corey', 'Adam', 'Steve', 'Rick', 'Thomas']
majors = ['Math', 'Engineering', 'CompSci', 'Arts', 'Business']

print('Memory (Before): {} Mb'.format(mem_profile.memory_usage_resource()))

def people_list(num_people):
    result = []
    for i in range(num_people):
        person = {
                    'id': i,
                    'name': random.choice(names),
                    'major': random.choice(majors)
                }
        result.append (person)
    return result

def people_generator(num_people):
    for i in range(num_people):
        person = {
                'id': i,
                'name': random.choice(names),
Beispiel #2
0
import mem_profile
import random
import time

names = ['Rick', 'John', 'Adam', 'Steve', 'Thomas']
majors = ['Math', 'Engineering', 'CompScience', 'Arts', 'Business']

print("Memory (Before): {} MB".format(mem_profile.memory_usage_resource()))


def people_list(num_people):
    result = []
    for i in range(num_people):
        person = {
            'id': i,
            'name': random.choice(names),
            'major': random.choice(majors)
        }
    result.append(person)
    return result


def people_generator(num_people):
    for i in range(num_people):
        person = {
            'id': i,
            'name': random.choice(names),
            'major': random.choice(majors)
        }
        yield person
Beispiel #3
0
import functools

n = [2, 3, 4, 5]
o = [1, 2, 3, 54]

print(list(map(lambda x: x**2, n)))

print(list(filter(lambda x: x > 2, n)))

print(functools.reduce(lambda x, y: x * y, n))

print(list(zip(n, o)))

import mem_profile

print(mem_profile.memory_usage_resource())
Beispiel #4
0
import mem_profile
import random
import time
names=['kanak','hasan','pabna']
majors=['c','c++','java']
print('memory(before):{}mb'.format(mem_profile.memory_usage_resource()))
def people_list(num_people):
    result=[]
    for i in xrange(num_people):
        person={
            'id':i,
            'name':random.choice(names),
            'major':random.choice(majors)
            }
        result.append(person)
        return result
def people_generator(num_people):
    for i in xrange(num_people):
        person={
            'id':i,
            'name':random.choice(names),
            'major':random.choice(majors)
            }
        yield person

t1=time.clock()
people=people_list(1000000)
t2=time.clock()

print('memory(after):{}mb'.format(mem_profile.memory_usage_resource()))
print('Took{}seconds'.format(t2-t1))
import mem_profile
import time


def function_one():
    pass


def function_two():
    pass


print('Memory BEFORE: {}Mb'.format(mem_profile.memory_usage_resource()))

timer_start = time.clock()
function_one()
timer_end = time.clock()

# timer_start = time.clock()
# function_two()
# timer_end = time.clock()

print('Memory AFTER: {}Mb'.format(mem_profile.memory_usage_resource()))
print('Took {} seconds'.format(timer_end - timer_start))