C++ Concerns: Timing Code, Random Numbers, Memory

Slides:



Advertisements
Similar presentations
Lecture 5: Floodfill. Floodfill Overview First assume that there are no walls Give each cell a distance from the goal. The goal has distance 0. Repeat.
Advertisements

Event-drive SimulationCS-2303, C-Term Project #3 – Event-driven Simulation CS-2303 System Programming Concepts (Slides include materials from The.
 Monday, 10/28/02, Slide #1 CS106 Introduction to CS1 Monday, 10/28/02  QUESTIONS on HW 03??  Today: Generating random numbers  Reading & exercises:
Processes CSCI 444/544 Operating Systems Fall 2008.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 12 – Craps Game Application: Introducing Random.
1 Random numbers Random  completely unpredictable. No way to determine in advance what value will be chosen from a set of equally probable elements. Impossible.
Data Structures Using C++ 2E Chapter 9 Searching and Hashing Algorithms.
Process Management. Processes Process Concept Process Scheduling Operations on Processes Interprocess Communication Examples of IPC Systems Communication.
Computer Science and Software Engineering University of Wisconsin - Platteville 2. Pointer Yan Shi CS/SE2630 Lecture Notes.
Iterative Constructs Review l What are named constants? Why are they needed? l What is a block? What is special about declaring a variable inside a block?
Week 7 - Wednesday.  What did we talk about last time?  scanf()  Memory allocation  malloc()  free()
 2008 Pearson Education, Inc. All rights reserved Case Study: Random Number Generation C++ Standard Library function rand – Introduces the element.
CS221 Random Numbers. Random numbers are often very important in programming Suppose you are writing a program to play the game of roulette The numbers.
CNIT 127: Exploit Development Ch 4: Introduction to Heap Overflows
RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals.
Lecture 2a: Performance Measurement. Goals of Performance Analysis The goal of performance analysis is to provide quantitative information about the performance.
Thread basics. A computer process Every time a program is executed a process is created It is managed via a data structure that keeps all things memory.
Random numbers in C++ Nobody knows what’s next....
Advanced loop controls. Loop Controls Recall from last week loop controls Event-controlled loops using sentinels repeats until a control variable takes.
CSC 413/513: Intro to Algorithms Hash Tables. ● Hash table: ■ Given a table T and a record x, with key (= symbol) and satellite data, we need to support:
Variables. A variable is a space in your robot’s memory where you can store data, such as whole numbers, decimal numbers, and words. Variable names follow.
Sections 10.5 – 10.6 Hashing.
lecture 5: CPU Scheduling
Chapter 1: Introduction
Current Generation Hypervisor Type 1 Type 2.
Data Watch Presenter Information Jason Puncher and François Tétreault
Data Structures Using C++ 2E
Why they aren't really random
Lesson Objectives Aims Key Words
7 Methods: A Deeper Look [2014Q2-ME2008].
CS 332: Algorithms Hash Tables David Luebke /19/2018.
Process Management Presented By Aditya Gupta Assistant Professor
Iterative Constructs Review
CMPT 201 Functions.
Data Structures Using C++ 2E
Deitel- C:How to Program (5ed)
Lab Session-9 CSIT-121 Spring 2005
Who’s in charge in there?
Chapter 6: CPU Scheduling
Chapter 5 - Functions Outline 5.1 Introduction
Control Structures (Structured Programming) for controlling the procedural aspects of programming CS1110 – Kaminski.
Building Java Programs
Objective of This Course
Dynamic Memory A whole heap of fun….
Memory Allocation CS 217.
ns-3 Waf build system ns-3 Annual Meeting June 2017
Iterative Constructs Review
Dynamic Memory A whole heap of fun….
Created by Hwansoo Han Edited by Ikjun Yeom
File Storage and Indexing
Chapter 6: CPU Scheduling
CS150 Introduction to Computer Science 1
Chapter 3: Processes.
Time Sources and Timing
C++ Concerns: Timing Code, Random Numbers, Memory
Dynamic Memory A whole heap of fun….
EXPRESSIONS, PAUSES AND SOUNDS
Measuring Experimental Performance
Dynamic Memory And Objects
Predefined Functions Revisited
Control Structures (Structured Programming) for controlling the procedural aspects of programming CS1110 – Kaminski.
CS 144 Advanced C++ Programming January 31 Class Meeting
COMP755 Advanced Operating Systems
Ns-3 Training Simulator core ns-3 training, June 2016.
Hello World Program In Visual Studio and Debugging
Week 7 - Friday CS222.
SPL – PS2 C++ Memory Handling.
CSE 303 Concepts and Tools for Software Development
Chapter 13: I/O Systems “The two main jobs of a computer are I/O and [CPU] processing. In many cases, the main job is I/O, and the [CPU] processing is.
Presentation transcript:

C++ Concerns: Timing Code, Random Numbers, Memory

Timing Method 1 : Stop watch Measure real "wall" time from start to end Other processes may have very direct impact

Timing Method 2 : Use OS tools to track process time *nix: "time myprogram.exe" Windows: use PowerShell and: "Measure-Command { myProgram.exe | Out-default }" Wall time only!

Instrumented Timing Method 3 : instrument code Add code to record elapsed processor time between points in code Targeted timing

<ctime> <ctime> library includes clock() : units of time since program launch c_type : type of data returned by clock() typedef of long on win32 g++ CLOCKS_PER_SECOND : defined value Integral type – careful with division 1000 on w32 g++

Timing Issues On Windows, clock() measures wall time elapsed On linux processor time elapsed Hard to measure short events Wrap in a loop and average

High Resolution Timing C++11 <chrono> library: http://www.guyrutenberg.com/2013/01/27/using-stdchronohigh_resolution_clock-example/ May support < 1 ms timers Not on Windows

Random Numbers

Random Test Data w/CStdLib Need cstdlib, possibly ctime srand(int) to seed rand() to get random integer

Random Test Data w/CStdLib Seed with: Constant for same sequence each time Time for random sequence Seed only ONCE per program

Random Test Data w/CStdLib Want a number between 0 & 1 millionish

Random Test Data w/CStdLib Want a number between 0 & 1 millionish Bad recipes: rand() only up to 32,000 rand() * 30 can only generate multiples of 30 number = 0 repeat 30 times: number += rand() normal distribution

Random Test Data w/CStdLib Better recipe for 0-999,999 :

Random with C++11 Random library: Random Engine: Object that can generate sequences

Random with C++11 Distribution: object that maps generated values onto desired range: Distribution object operates on generator to produce value:

Stack vs Heap

Stack = limited space Values allocated on the stack have limited lifespan VERY limited space available Large arrays will crash program at start

Heap = Heap allocations (using new) live until deleted Large amounts of space available Where you need to put any large arrays