Cost of Your Programs

Similar documents
The RAM Computation Model

Binary Search and Worst-Case Analysis

Lec 3. Compilers, Debugging, Hello World, and Variables

CHAPTER 1 Introduction to Computers and Java

CS 31: Intro to Systems Caching. Martin Gagne Swarthmore College March 23, 2017

Software Development. Integrated Software Environment

Kampala August, Agner Fog

Lecture 1: Course Overview

Chapter 1: Introduction to Computers and Java

8/23/2014. Chapter Topics. Introduction. Java History. Why Program? Java Applications and Applets. Chapter 1: Introduction to Computers and Java

Assembly Language for Intel-Based Computers, 4 th Edition. Chapter 1: Basic Concepts

Memory systems. Memory technology. Memory technology Memory hierarchy Virtual memory

CS 351 Final Exam Solutions

CSI32 Object-Oriented Programming

Electronics Single Board Computers

Problem Solving and Program Design - Chapter 1. Cory L. Strope

From High Level to Machine Code. Compilation Overview. Computer Programs

Professor Hugh C. Lauer CS-1004 Introduction to Programming for Non-Majors

Programming 1 - Honors

Operating Systems. Operating System Structure. Lecture 2 Michael O Boyle

Simplicity and minimalism in software development

An Introduction to Python (TEJ3M & TEJ4M)

Introduction to Programming: Variables and Objects. HORT Lecture 7 Instructor: Kranthi Varala

Chapter 5 C. Virtual machines

Computer Architecture and Organization. Instruction Sets: Addressing Modes and Formats

Basics of Computing Ed Gatzke,

Computer Basics 1/24/13. Computer Organization. Computer systems consist of hardware and software.

Recursion: The Beginning

Binary Search and Worst-Case Analysis

INF 212 ANALYSIS OF PROG. LANGS PLUGINS. Instructors: Crista Lopes Copyright Instructors.

OO software systems are systems of interacting objects.

k-selection Yufei Tao Department of Computer Science and Engineering Chinese University of Hong Kong

Data Types. (with Examples In Haskell) COMP 524: Programming Languages Srinivas Krishnan March 22, 2011

CSI31 Introduction to Computer Programming I. Dr. Sharon Persinger Fall

CSCE150A. Administrivia. Overview. Hardware. Software. Example. Program. Pseudocode. Flowchart. Control Structures. Hello World Program CSCE150A

Computer Science & Engineering 150A Problem Solving Using Computers

Computers in Engineering COMP 208. Computer Structure. Computer Architecture. Computer Structure Michael A. Hawker

Reversing. Time to get with the program

Introduction to Scientific Computing

CPU Architecture system clock

What is Java Platform?

CS Basics 2) Architecture

Computer Basics 1/6/16. Computer Organization. Computer systems consist of hardware and software.

CENG3420 Lab 1-1: MIPS assembly language programing

Assembly Language for Intel-Based Computers, 4 th Edition. Chapter 2: IA-32 Processor Architecture Included elements of the IA-64 bit

What is This Course About? CS 356 Unit 0. Today's Digital Environment. Why is System Knowledge Important?

Groups of two-state devices are used to represent data in a computer. In general, we say the states are either: high/low, on/off, 1/0,...

The Art of Parallel Processing

Interlude. Why Object Oriented Programming?

Making Address Spaces Smaller

COMP Computer Basics. Yi Hong May 13, 2015

CS 220: Introduction to Parallel Computing. Beginning C. Lecture 2

Computer Architecture Dr. Charles Kim Howard University

I/O Systems. Amir H. Payberah. Amirkabir University of Technology (Tehran Polytechnic)

Replacing the Colored Accent Ring EXTREME-PERFORMANCE 240MM LIQUID CPU COOLER QUICK START GUIDE

Chapter 1 Welcome Aboard

Caching Basics. Memory Hierarchies

SECTION 1: CODE REASONING + VERSION CONTROL + ECLIPSE

Introduction. Arizona State University 1

Programming 1. Lecture 1 COP 3014 Fall August 28, 2017

H115i QUICK START GUIDE

H.-S. Oh, B.-J. Kim, H.-K. Choi, S.-M. Moon. School of Electrical Engineering and Computer Science Seoul National University, Korea

William Stallings Computer Organization and Architecture 8 th Edition. Chapter 11 Instruction Sets: Addressing Modes and Formats

CSC180: Lecture 2. Wael Aboulsaadat.

CS370 Operating Systems

SAP Crystal Reports for Eclipse Product Availability Matrix (PAM)

CS187 - Science Gateway Seminar for CS and Math

CS103 Lecture 1 Slides. Introduction Mark Redekopp

Lecture 15: Network File Systems

Chapter 2: Operating-System Structures. Operating System Concepts 9 th Edit9on

CS101 Lecture 25: The Machinery of Computation: Computer Architecture. John Magee 29 July 2013 Some material copyright Jones and Bartlett

Lecture 11. Example 1. Introduction. Method definition and invocation. Parameter passing: value vs. reference parameters. Scope and Lifetime.

Basic Concepts COE 205. Computer Organization and Assembly Language Dr. Aiman El-Maleh

Outline. Introduction to Programming (in C++) Introduction. First program in C++ Programming examples

Best Practices: Coding Questions For Engineers

Week 1 Introduction to Computer and Algorithm (Part1) UniMAP Sem II 11/12 DKT121: Basic Computer Programming 1

Programming Language Concepts Object-Oriented Programming. Janyl Jumadinova 28 February, 2017

SKILL AREA 304: Review Programming Language Concept. Computer Programming (YPG)

Analysis of Algorithms. 5-Dec-16

CS 1713 Introduction to Computer Programming II Ch 0 Overview - Problem solving

Data Structures and Programming with C++

Tunneling. Encapsulation and Tunneling. Performance implications of data transmission on high speed network devices

More on Address Translation. CS170 Fall T. Yang Some of slides from UCB CS162 by Kubiatowicz

CSCI 402: Computer Architectures. Instructions: Language of the Computer (4) Fengguang Song Department of Computer & Information Science IUPUI

CS356: Discussion #9 Memory Hierarchy and Caches. Marco Paolieri Illustrations from CS:APP3e textbook

CmSc 150 Fundamentals of Computing I. Lesson 28: Introduction to Classes and Objects in Java. 1. Classes and Objects

Chapter. Focus of the Course. Object-Oriented Software Development. program design, implementation, and testing

Welcome to Computer Organization and Design Logic CS 64: Computer Organization and Design Logic Lecture #1 Winter 2018

Java Object Oriented Design. CSC207 Fall 2014

CSE 153 Design of Operating Systems

CPE 101. Overview. Programming vs. Cooking. Key Definitions/Concepts B-1

Object Orientated Analysis and Design. Benjamin Kenwright

CS 371L - Mobile Computing (ios) Dr. William C. Bulko. CS 371L Mobile Computing (ios) Introduction

Lecture 8 Memory Management Strategies (chapter 8)

Operating System Services. User Services. System Operation Services. User Operating System Interface - CLI. A View of Operating System Services

Typed Assembly Language for Implementing OS Kernels in SMP/Multi-Core Environments with Interrupts

A+ Guide to Managing & Maintaining Your PC, 8th Edition. Chapter 5 Supporting Processors and Upgrading Memory

Compiler Construction D7011E

+ Random-Access Memory (RAM)

Cross Compiling. Real Time Operating Systems and Middleware. Luca Abeni

Transcription:

Department of Computer Science and Engineering Chinese University of Hong Kong

In the class, we have defined the RAM computation model. In turn, this allowed us to define rigorously algorithms and their cost. In reality, we do not write programs under the RAM model instead, we do so in a programming language like C++, JAVA, Python, etc. Thus, how would you measure the cost of your programs? Also, what are the connections to the RAM model? This side talk will clarify these issues.

Measuring the Cost of Your Program Rule of Thumb: Count the number of statements executed. In other words, to make your program fast, minimize the number of statements that need to be run.

Example int i = 0; int n = 100; int sum = 0; for (i = 1; i <= n; i ++) { sum = sum + i; } return sum; Number of statements executed = 3n + 5 (in this example, n = 100). This is an accurate indication of the cost of your algorithm in the RAM model, up to only a constant factor. The next slide explains why.

Example... i sum n When your program is executed, the computer (the real one where your program is run) assigns a memory cell for each variable. The figure above shows an example note that the 3 memory cells can be anywhere, and in any order.

Example... i sum n A statement like i = 0 gets automatically translated into a sequence of atomic operations in the RAM model, e.g.: set Register 1 to value 0 set Register 2 to value the address of i write the contents of Register 1 into memory cell i In this example, the statement i = 0 entails a cost of 3 in the RAM model.

Example... i sum n As another example, statement sum = sum + i may get translated into 6 atomic operations: set Register 1 to the address of i load i into Register 2 set Register 1 to the address of sum load sum into Register 3 Register 3 Register 2 + Register 3 write the contents of Register 3 into memory cell sum

Who Does the Translation? The compiler. When you are coding, you are writing in a so-called high level language where each statement encapsulates multiple atomic operations, so that you do not need to worry about the low-level details such as registers. When you are done, the compiler does the dirty work by transforming your code into a form that can actually be executed perhaps you have heard about the name of that form : the assembly language.

Take-Away Message 1 The number of statements executed in your program can be regarded as the running time of your program it differs from the RAM-model cost by at most a constant. For example, the constant is 6, if every statement gets translated to up to 6 atomic operations.

Take-Away Message 2 This gives one more reason why in computer science we seldom care about constants in analyzing the cost of an algorithm. Specifically, how a compiler translates your source code differs from language to language (C++ vs. JAVA), version to version (compiler 1.0 vs. 2.0), platform to platform (Windows vs. Linux), and CPU to CPU (Intel vs. AMD). It is possible that one compiler may convert sum = sum + i into 6 operations, while another may do so with only 3. Thus, although your program has only 2n statements, there is no guarantee that it will have fewer atomic operations than another 10n-statement program.