SlideShare a Scribd company logo
1 of 4
7.1 Empirical measurements
We can measure the cost of evaluating a given expression empirically. If we are
primarily concerned with time, we could just use a stopwatch to measure the evaluation
time.
For more accurate results, we use the built-in (time Expression) special
form.1 Evaluating (time Expression) produces the value of the input expression, but also
prints out the time required to evaluate the expression (shown in our examples
using slanted font). It prints out three time values:
The time in milliseconds the processor ran to evaluate the expression. CPU is an
abbreviation for “central processing unit”, the computer’s main processor.
The actual time in milliseconds it took to evaluate the expression. Since other processes
may be running on the computer while this expression is evaluated, the real time may be
longer than the CPU time, which only counts the time the processor was working
on evaluating this expression.
The time in milliseconds the interpreter spent on garbage collection to evaluate
the expression. Garbage collection is used to reclaim memory that is storing data that
will never be used again.
For example, using the definitions from Chapter 5,
(time (solve-pegboard (board-remove-peg (make-board 5)
(make-position 11))))
prints: cpu time: 141797 real time: 152063 gc time: 765. The real time is 152 seconds,
meaning this evaluation took just over two and a half minutes.
Of this time, the evaluation was using the CPU for 142 seconds, and the garbage
collector ran for less than one second.
Here are two more examples:
> (time
cpu
1
> (time
cpu
(car
tim
e:
(list-append
531
real
(intsto
time:
1000)
531
(intsto
time:
100))))
62gc
(car
tim
e:
(list-append
609
real
(intsto
time:
1000)
609
(intsto 100))))
0gc time:
The two expressions evaluated are identical, but the reported time varies. Even on the
same computer, the time needed to evaluate the same expression varies.
Many properties unrelated to our expression (such as where things happen to be stored
in memory) impact the actual time needed for any particular evaluation.
Hence, it is dangerous to draw conclusions about which procedure is faster based on a
few timings.
Another limitation of this way of measuring cost is it only works if we wait for
the evaluation to complete.
If we try an evaluation and it has not finished after an hour, say, we have no idea if the
actual time to finish the evaluation is sixty-one minutes or a quintillion years.
We could wait another minute, but if it still hasn’t finished we don’t know if the
execution time is sixty-two minutes or a quintillion years.
The techniques we develop allow us to predict the time an evaluation needs
without waiting for it to execute.
There’s no sense in being precise when you don’t even know what you’re talking about.
John von Neumann Finally, measuring the time of a particular application of a
procedure does not provide much insight into how long it will take to apply the
procedure to different inputs.
We would like to understand how the evaluation time scales with the size of the inputs
so we can understand which inputs the procedure can sensibly be applied to, and can
choose the best procedure to use for different situations.
The next section introduces mathematical tools that are helpful for capturing how cost
scales with input size.
Exercise 7.1. Suppose you are defining a procedure that needs to append two lists, one
short list, short and one very long list, long, but the order of elements in the resulting list
does not matter. Is it better to use (list-append short long)or (list-append long short)?
(A good answer will involve both experimental results and an analytical explanation.)

More Related Content

Viewers also liked (19)

Lighting for displays and signaling
Lighting for displays and signalingLighting for displays and signaling
Lighting for displays and signaling
 
lists
listslists
lists
 
impact of_mutation
impact of_mutationimpact of_mutation
impact of_mutation
 
evaluating recursive_applications
evaluating recursive_applicationsevaluating recursive_applications
evaluating recursive_applications
 
Array- queues3
Array- queues3Array- queues3
Array- queues3
 
Stacks queues
Stacks queuesStacks queues
Stacks queues
 
1.2 eye & vision
1.2 eye & vision1.2 eye & vision
1.2 eye & vision
 
assignment
assignmentassignment
assignment
 
pairs
pairspairs
pairs
 
python
pythonpython
python
 
Transport lighting
Transport lightingTransport lighting
Transport lighting
 
Flood & sports
Flood & sportsFlood & sports
Flood & sports
 
Quick sort
Quick sortQuick sort
Quick sort
 
Pda to cfg h2
Pda to cfg h2Pda to cfg h2
Pda to cfg h2
 
Multi dimensional array
Multi dimensional arrayMulti dimensional array
Multi dimensional array
 
Shell sort
Shell sortShell sort
Shell sort
 
Np completeness h4
Np completeness  h4Np completeness  h4
Np completeness h4
 
Two dimensional array
Two dimensional arrayTwo dimensional array
Two dimensional array
 
Turing Machine
Turing MachineTuring Machine
Turing Machine
 

Similar to empirical masurements

lec3 (1).ppt megerments for peromomence
lec3 (1).ppt megerments   for peromomencelec3 (1).ppt megerments   for peromomence
lec3 (1).ppt megerments for peromomence
MadhuGupta99385
 
algocomplexity cost effective tradeoff in
algocomplexity cost effective tradeoff inalgocomplexity cost effective tradeoff in
algocomplexity cost effective tradeoff in
javed75
 
Industrial egineering
Industrial egineeringIndustrial egineering
Industrial egineering
Rajeev Sharan
 
presentationfinal-090714235255-phpapp01 (1) (2).pptx
presentationfinal-090714235255-phpapp01 (1) (2).pptxpresentationfinal-090714235255-phpapp01 (1) (2).pptx
presentationfinal-090714235255-phpapp01 (1) (2).pptx
javed75
 
Iasi code camp 12 october 2013 performance testing for web applications with...
Iasi code camp 12 october 2013  performance testing for web applications with...Iasi code camp 12 october 2013  performance testing for web applications with...
Iasi code camp 12 october 2013 performance testing for web applications with...
Codecamp Romania
 
Performance analysis and randamized agoritham
Performance analysis and randamized agorithamPerformance analysis and randamized agoritham
Performance analysis and randamized agoritham
lilyMalar1
 

Similar to empirical masurements (20)

Chapter 1 Data structure.pptx
Chapter 1 Data structure.pptxChapter 1 Data structure.pptx
Chapter 1 Data structure.pptx
 
lec3 (1).ppt megerments for peromomence
lec3 (1).ppt megerments   for peromomencelec3 (1).ppt megerments   for peromomence
lec3 (1).ppt megerments for peromomence
 
Daa notes 1
Daa notes 1Daa notes 1
Daa notes 1
 
algocomplexity cost effective tradeoff in
algocomplexity cost effective tradeoff inalgocomplexity cost effective tradeoff in
algocomplexity cost effective tradeoff in
 
Industrial egineering
Industrial egineeringIndustrial egineering
Industrial egineering
 
complexity.pptx
complexity.pptxcomplexity.pptx
complexity.pptx
 
presentationfinal-090714235255-phpapp01 (1) (2).pptx
presentationfinal-090714235255-phpapp01 (1) (2).pptxpresentationfinal-090714235255-phpapp01 (1) (2).pptx
presentationfinal-090714235255-phpapp01 (1) (2).pptx
 
Complexity of Algorithm
Complexity of AlgorithmComplexity of Algorithm
Complexity of Algorithm
 
Iasi code camp 12 october 2013 performance testing for web applications with...
Iasi code camp 12 october 2013  performance testing for web applications with...Iasi code camp 12 october 2013  performance testing for web applications with...
Iasi code camp 12 october 2013 performance testing for web applications with...
 
DA lecture 3.pptx
DA lecture 3.pptxDA lecture 3.pptx
DA lecture 3.pptx
 
Measuring Performance by Irfanullah
Measuring Performance by IrfanullahMeasuring Performance by Irfanullah
Measuring Performance by Irfanullah
 
Fundamentals of the Analysis of Algorithm Efficiency
Fundamentals of the Analysis of Algorithm EfficiencyFundamentals of the Analysis of Algorithm Efficiency
Fundamentals of the Analysis of Algorithm Efficiency
 
Data structure introduction
Data structure introductionData structure introduction
Data structure introduction
 
Optimal Round Robin CPU Scheduling Algorithm using Manhattan Distance
Optimal Round Robin CPU Scheduling Algorithm using Manhattan Distance Optimal Round Robin CPU Scheduling Algorithm using Manhattan Distance
Optimal Round Robin CPU Scheduling Algorithm using Manhattan Distance
 
Performance analysis and randamized agoritham
Performance analysis and randamized agorithamPerformance analysis and randamized agoritham
Performance analysis and randamized agoritham
 
L07_performance and cost in advanced hardware- computer architecture.pptx
L07_performance and cost in advanced hardware- computer architecture.pptxL07_performance and cost in advanced hardware- computer architecture.pptx
L07_performance and cost in advanced hardware- computer architecture.pptx
 
An Autonomous Self-Assessment Application to Track the Efficiency of a System...
An Autonomous Self-Assessment Application to Track the Efficiency of a System...An Autonomous Self-Assessment Application to Track the Efficiency of a System...
An Autonomous Self-Assessment Application to Track the Efficiency of a System...
 
G017113537
G017113537G017113537
G017113537
 
TEMPORALLY EXTENDED ACTIONS FOR REINFORCEMENT LEARNING BASED SCHEDULERS
TEMPORALLY EXTENDED ACTIONS FOR REINFORCEMENT LEARNING BASED SCHEDULERSTEMPORALLY EXTENDED ACTIONS FOR REINFORCEMENT LEARNING BASED SCHEDULERS
TEMPORALLY EXTENDED ACTIONS FOR REINFORCEMENT LEARNING BASED SCHEDULERS
 
Temporally Extended Actions For Reinforcement Learning Based Schedulers
Temporally Extended Actions For Reinforcement Learning Based Schedulers Temporally Extended Actions For Reinforcement Learning Based Schedulers
Temporally Extended Actions For Reinforcement Learning Based Schedulers
 

More from Rajendran

More from Rajendran (20)

Element distinctness lower bounds
Element distinctness lower boundsElement distinctness lower bounds
Element distinctness lower bounds
 
Scheduling with Startup and Holding Costs
Scheduling with Startup and Holding CostsScheduling with Startup and Holding Costs
Scheduling with Startup and Holding Costs
 
Divide and conquer surfing lower bounds
Divide and conquer  surfing lower boundsDivide and conquer  surfing lower bounds
Divide and conquer surfing lower bounds
 
Red black tree
Red black treeRed black tree
Red black tree
 
Hash table
Hash tableHash table
Hash table
 
Medians and order statistics
Medians and order statisticsMedians and order statistics
Medians and order statistics
 
Proof master theorem
Proof master theoremProof master theorem
Proof master theorem
 
Recursion tree method
Recursion tree methodRecursion tree method
Recursion tree method
 
Recurrence theorem
Recurrence theoremRecurrence theorem
Recurrence theorem
 
Master method
Master method Master method
Master method
 
Master method theorem
Master method theoremMaster method theorem
Master method theorem
 
Hash tables
Hash tablesHash tables
Hash tables
 
Lower bound
Lower boundLower bound
Lower bound
 
Master method theorem
Master method theoremMaster method theorem
Master method theorem
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
 
Longest common subsequences in Algorithm Analysis
Longest common subsequences in Algorithm AnalysisLongest common subsequences in Algorithm Analysis
Longest common subsequences in Algorithm Analysis
 
Dynamic programming in Algorithm Analysis
Dynamic programming in Algorithm AnalysisDynamic programming in Algorithm Analysis
Dynamic programming in Algorithm Analysis
 
Average case Analysis of Quicksort
Average case Analysis of QuicksortAverage case Analysis of Quicksort
Average case Analysis of Quicksort
 
Np completeness
Np completenessNp completeness
Np completeness
 
computer languages
computer languagescomputer languages
computer languages
 

Recently uploaded

Recently uploaded (20)

The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDF
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
 
Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhĐề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 

empirical masurements

  • 1. 7.1 Empirical measurements We can measure the cost of evaluating a given expression empirically. If we are primarily concerned with time, we could just use a stopwatch to measure the evaluation time. For more accurate results, we use the built-in (time Expression) special form.1 Evaluating (time Expression) produces the value of the input expression, but also prints out the time required to evaluate the expression (shown in our examples using slanted font). It prints out three time values: The time in milliseconds the processor ran to evaluate the expression. CPU is an abbreviation for “central processing unit”, the computer’s main processor. The actual time in milliseconds it took to evaluate the expression. Since other processes may be running on the computer while this expression is evaluated, the real time may be longer than the CPU time, which only counts the time the processor was working on evaluating this expression. The time in milliseconds the interpreter spent on garbage collection to evaluate the expression. Garbage collection is used to reclaim memory that is storing data that will never be used again. For example, using the definitions from Chapter 5, (time (solve-pegboard (board-remove-peg (make-board 5) (make-position 11))))
  • 2. prints: cpu time: 141797 real time: 152063 gc time: 765. The real time is 152 seconds, meaning this evaluation took just over two and a half minutes. Of this time, the evaluation was using the CPU for 142 seconds, and the garbage collector ran for less than one second. Here are two more examples: > (time cpu 1 > (time cpu (car tim e: (list-append 531 real (intsto time: 1000) 531 (intsto time: 100)))) 62gc (car tim e: (list-append 609 real (intsto time: 1000) 609 (intsto 100)))) 0gc time: The two expressions evaluated are identical, but the reported time varies. Even on the same computer, the time needed to evaluate the same expression varies. Many properties unrelated to our expression (such as where things happen to be stored in memory) impact the actual time needed for any particular evaluation. Hence, it is dangerous to draw conclusions about which procedure is faster based on a few timings.
  • 3. Another limitation of this way of measuring cost is it only works if we wait for the evaluation to complete. If we try an evaluation and it has not finished after an hour, say, we have no idea if the actual time to finish the evaluation is sixty-one minutes or a quintillion years. We could wait another minute, but if it still hasn’t finished we don’t know if the execution time is sixty-two minutes or a quintillion years. The techniques we develop allow us to predict the time an evaluation needs without waiting for it to execute. There’s no sense in being precise when you don’t even know what you’re talking about. John von Neumann Finally, measuring the time of a particular application of a procedure does not provide much insight into how long it will take to apply the procedure to different inputs. We would like to understand how the evaluation time scales with the size of the inputs so we can understand which inputs the procedure can sensibly be applied to, and can choose the best procedure to use for different situations. The next section introduces mathematical tools that are helpful for capturing how cost scales with input size.
  • 4. Exercise 7.1. Suppose you are defining a procedure that needs to append two lists, one short list, short and one very long list, long, but the order of elements in the resulting list does not matter. Is it better to use (list-append short long)or (list-append long short)? (A good answer will involve both experimental results and an analytical explanation.)