Assignment Part 2
CT070-3-3-DPAT (052024-MER)
Design Patterns
APD3F2405SE
Name: Alvin Jose Joshy
Student ID: TP067879
Lecturer Name: Assoc. Prof. Dr. Muhammad Ehsan Rana
Hand in Date: 18/08/2024
Table of Content
Methodology....................................................................................................................................1
Turnaround Time Measurement..................................................................................................1
Memory Utilization Measurement...............................................................................................2
Results and Comparative Evaluation...............................................................................................6
1. Introduction..............................................................................................................................6
2. Execution Time Analysis.........................................................................................................6
3. Memory Usage Analysis..........................................................................................................7
4. Comparative Discussion..........................................................................................................7
5. Conclusion...............................................................................................................................8
Conclusion.......................................................................................................................................8
References........................................................................................................................................9
Methodology
Turnaround Time Measurement
Turnaround time is a crucial metric for evaluating the performance of a system or application. It
is measured from the moment a task is initiated until it is completed (Tigulla & Kalidasu, 2015).
The following steps were taken to measure the turnaround time for the tasks in this project:
Identify the Start Point: The start of the turnaround time is marked by the initiation of
the task. In this context, this could be when the system begins processing a request or
when a particular function or operation is invoked.
Identify the End Point: The turnaround time concludes when the task is completed and
the results are available. For instance, this could be when a process finishes its execution
and the output is produced.
1|Page
Measure the Time Interval: The total turnaround time is calculated as the difference
between the end time and the start time. This can be efficiently measured using system
clocks or timers embedded in the code. The formula for this calculation is as follows:
Turnaround Time = End Time − Start Time
Figure 19: Screenshot of Methodology used 1
Figure 20: Screenshot of Methodology used 2
Figure 21: Screenshot of Methodology used 3
Average Turnaround Time: To gauge overall system performance, the average
turnaround time across multiple tasks was calculated using the formula:
Average Turnaround Time = sum of all turnaround times / number of times run
2|Page
Memory Utilization Measurement
Memory utilization was another critical factor measured during the execution of tasks. The
difference in memory usage before and after the execution provided insights into the memory
efficiency of the application. The Java code snippet used to measure memory utilization is shown
above, where the memory used by the task is calculated as the difference between the memory
used before and after the task’s execution.
Screenshots of Results
Figure 22: Screenshot of Basic Code Results 1
3|Page
Figure 23: Screenshot of Basic Code Results 2
Figure 24: Screenshot of Basic Code Results 3
4|Page
Figure 25: Screenshot of Refined Code Results 1
Figure 26: Screenshot of Refined Code Results 2
5|Page
Figure 27: Screenshot of Refined Code Results 3
Results and Comparative Evaluation
1. Introduction
By tracking the execution time and memory consumption over five runs for every version, the
performance of the original and improved code snippets was assessed. The main goal was to
evaluate the efficiency gains achieved in the improved version and ascertain the degree to which
these modifications improved performance as a whole. In order to optimize system resources and
enhance application responsiveness, the comparison study focuses on reducing execution time
and memory consumption.
2. Execution Time Analysis
The basic code sample executed in an average of roughly 51.5 milliseconds, but it might take
anywhere from 44.2 to 57.4 milliseconds to execute. Variability in execution durations is
common in settings where there are background processes or slight variations in the system load.
The optimized code sample, on the other hand, showed a significant decrease in execution time,
with values ranging from around 6.4 to 10.6 milliseconds and an average of 8.2 milliseconds.
With the improved code attaining an over 85% reduction in average execution time over the
simple version, this is a major performance increase. The improvement can be ascribed to
resource management, algorithms, and code structure optimizations that made it possible for the
6|Page
improved code to run more quickly. This decrease in execution time suggests that the code
refined using design patterns can handle jobs more quickly, which makes it more appropriate for
applications where speed is a crucial consideration in a time-sensitive manner.
3. Memory Usage Analysis
The basic code sample used about 3,999,224 bytes of memory during execution, which was the
same for all five runs. On the other hand, the optimized code fragment continuously consumed
around 1,331,712 bytes of RAM. This decrease corresponds to a roughly 66.7% decrease in
memory consumption.
The updated code has been optimized to use less resources due to enhanced data structures,
smaller memory allocations, or better memory management techniques, as evidenced by the
notable decrease in memory consumption. Reduced memory use lessens the chance of memory-
related problems like leaks or overflows, which over time can cause instability in the system. It
also helps to reduce the total resource footprint.
4. Comparative Discussion
The execution time and memory use of the basic and refined code snippets are significantly
improved, according to the comparison study. The improved code showed a notable
improvement in performance, with execution times down by roughly 85% and memory
consumption down by roughly 67%. These outcomes highlight how well the adjustments made
in the improved version worked.
The optimized code is more scalable since it can manage heavier loads or carry out more
operations in the same amount of time as the basic code thanks to the improvements in execution
time. Furthermore, the code can run more smoothly on systems with constrained memory or in
settings where memory is a major limitation because to the decrease in memory utilization.
All things considered, the improved code sample uses a lot less resources while still performing
better. These improvements make the program more responsive and resource-efficient,
underscoring the significance of performance tuning and iterative code improvement in software
development.
7|Page
5. Conclusion
The comparison analysis makes the advantages of code optimization very evident. Code
optimization resulted in much shorter execution times and much less memory usage, making the
software more effective and efficient. The application will be better able to meet performance
objectives and manage demanding workloads in a variety of situations thanks to these upgrades,
which are in line with the goals of enhancing system performance and resource management.
Conclusion
Software efficiency is a complex problem that calls for a methodical approach to software
development and design. As this project demonstrates, design patterns are essential to this effort
because they provide organized, reusable answers to typical design issues that have the potential
to adversely affect software efficiency. Developers can produce software systems that are not
only highly efficient but also simpler to scale, maintain, and adjust to changing needs by
implementing design patterns.
Using design patterns like State and Facade during the refactoring process has tangible
advantages, as demonstrated by the case study on the Car Rental Management System. Software
efficiency significantly increases when these patterns are used to optimize resource utilization,
streamline code structure, and cut down on redundancy. Design patterns facilitate more effective
use of system resources by streamlining the development process and abstracting complicated
interactions into clear interfaces.
The project also emphasizes how using design patterns to software development has wider
ramifications. By encouraging excellent practices in code organization and modularity, design
patterns support long-term software system sustainability beyond short-term performance
advantages. Consequently, there is a decreased chance of accruing technical debt, which might
eventually worsen system performance.
8|Page
In conclusion, establishing and sustaining software efficiency requires the incorporation of
design patterns throughout the software development lifecycle, especially during refactoring. The
ideas and procedures described in this paper will be increasingly important for developers
looking to optimize their software systems as systems get more sophisticated. Developers can
write software that not only satisfies present performance requirements but also is resilient and
adaptable enough to address new difficulties in the future by utilizing design patterns. Design
patterns are therefore a vital tool in the creation of effective, high-caliber software systems.
References
Langsari, K., Rochimah, S., & Akbar, R. J. (2018). Measuring Performance Efficiency of
Application applying Design Patterns and Refactoring Method. IPTEK Journal of
Proceedings Series, 4(1), 149. https://doi.org/10.12962/j23546026.y2018i1.3527
9|Page