Skip to content

Commit 5a60f81

Browse files
committed
Found a timing bug and fixed it immediatly. Also added some timing stats to look at
1 parent acb62c5 commit 5a60f81

File tree

3 files changed

+50
-26
lines changed

3 files changed

+50
-26
lines changed

11808206_exercise_1.py

+47-26
Original file line numberDiff line numberDiff line change
@@ -694,40 +694,60 @@ def time_steps(observations, date):
694694
# TODO: your changes here
695695
# load all data
696696
time_load = 0
697-
start_load = time.process_time()
698-
load_all_data(observations)
699-
end_load = time.process_time()
700-
time_load = end_load - start_load
697+
for i in range(3):
698+
start_load = time.process_time()
699+
700+
load_all_data(observations)
701+
702+
end_load = time.process_time()
703+
time_load += (end_load - start_load)
704+
time_load = time_load / 3
701705
#print("Time load:",time_load)
702706

703707
# retrieve (aggregated) values for day, week, month and year
704708
time_day = 0
705-
start_day = time.process_time()
706-
time_day = observations.day(date)
707-
end_day = time.process_time()
708-
time_day = end_day - start_day
709+
for i in range(3):
710+
start_day = time.process_time()
711+
712+
observations.day(date)
713+
714+
end_day = time.process_time()
715+
time_day += (end_day - start_day)
716+
time_day = time_day / 3
709717
#print("Time day:",time_day)
710718

711719
time_week = 0
712-
start_week = time.process_time()
713-
time_week = observations.week(date)
714-
end_week = time.process_time()
715-
time_week = end_week - start_week
720+
for i in range(3):
721+
start_week = time.process_time()
722+
723+
observations.week(date)
724+
725+
end_week = time.process_time()
726+
time_week += (end_week - start_week)
727+
time_week = time_week / 3
716728
#print("Time week:",time_week)
717729

718730
time_month = 0
719-
start_month = time.process_time()
720-
time_month = observations.month(date)
721-
end_month = time.process_time()
722-
time_month = end_month - start_month
731+
for i in range(3):
732+
start_month = time.process_time()
733+
734+
observations.month(date)
735+
736+
end_month = time.process_time()
737+
time_month += (end_month - start_month)
738+
time_month = time_month / 3
723739
#print("Time month:",time_month)
724740

725741

726742
time_year = 0
727-
start_year = time.process_time()
728-
time_year = observations.year(date)
729-
end_year = time.process_time()
730-
time_year = end_year - start_year
743+
for i in range(3):
744+
start_year = time.process_time()
745+
746+
observations.year(date)
747+
748+
end_year = time.process_time()
749+
time_year += (end_year - start_year)
750+
time_year = time_year / 3
731751
#print("Time year:",time_year)
732752

733753
# return the recorded timings
@@ -742,17 +762,17 @@ def evaluate():
742762

743763
# TODO: your changes here
744764
# object oriented
745-
#print("Objectoriented")
765+
print("Objectoriented")
746766
obs_oo = WeatherObservationsObjectOriented()
747767
times_oo = time_steps(obs_oo, datetime.date(2012, 1, 1))
748768

749769
# data oriented
750-
#print("Dataoriented")
770+
print("\nDataoriented")
751771
obs_do = WeatherObservationsDataOriented()
752772
times_do = time_steps(obs_do, datetime.date(2012, 1, 1))
753773

754774
# data oriented w/ numpy
755-
#print("Numpy")
775+
print("\nNumpy")
756776
obs_np = WeatherObservationsDataOrientedNumpy()
757777
times_np = time_steps(obs_np, datetime.date(2012, 1, 1))
758778

@@ -770,10 +790,11 @@ def solution_task_4():
770790
# TODO: your changes here
771791
return '''
772792
For the measuring of the time I used the time module for python. The reason is that there were some problems with parameters using the timeit implementation.
773-
According to the measurements the Dataoriented Approach (without Numpy) is the fastest one for loading the date and numpy is the slowest. That's obvious because numpy is not designed for single element operations, it's designed to work on enormous datasets.
774-
That's the reason why numpy is in finding the mean for a certain month, week and year the fastest.
793+
According to the measurements the Dataoriented Approach (without Numpy) is the fastest one for loading the date and a few miliseconds numpy slower. That's obvious because numpy is not designed for single element operations, it's designed to work on enormous datasets which are already preloaded.
794+
Therefore the numpy (and also the Dataoriented) approach are a lot slower doing single element operations than the objectoriented one.
795+
On the other side numpy is in finding the mean for a certain month, week and year the fastest, because in thoose scenarios the way its working is at its best.
775796
Among the data oriented and object oriented approach is nearly no differences. Sometimes the object oriented is 0.002 seconds faster and sometimes the other way around
776-
All in all it's safe to say that numpy isn't that fast loading the data, but it can work really fast on aggregated Data.
797+
All in all it's safe to say that numpy isn't that fast loading the data, but it can work really fast on aggregated Data. On the other hand it is better to use objects for single element operations
777798
'''
778799

779800

Performance.png

75 KB
Loading

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Dataoriented Programming vs. Objectoriented Programming
22

3+
## Performance Stats
4+
![Performance Stats](./Performance.png "Performance Stats")
5+
36

47
## Tasks
58
### Task1

0 commit comments

Comments
 (0)