Comparing Compiled and Interpreted Programs: Understanding Computer Speed and Algorithms, Study notes of Computer Science

An introduction to media computation, discussing the concepts of compilation and interpretation, the complexity of algorithms, and the role of hardware in computer processing. It compares compiled and interpreted programs, using examples like adobe photoshop and java, and explains the advantages and disadvantages of each. Additionally, it introduces the concept of the traveling salesman problem and its current limitations in finding optimal solutions.

Typology: Study notes

Pre 2010

Uploaded on 08/04/2009

koofers-user-pie
koofers-user-pie 🇺🇸

9 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
CS1315:
Introduction to
Media Computation
Speed and Complexity
Why is Photoshop so much faster?
Today’s class
Compilation and interpretation
Assembly language
Interpreters
Compilers
Complexity of algorithms
Hardware
Each
kind
of processor has its own
machine language
Apple computers typically
use CPU (processor)
chips called G4 or G5.
Computers running
Microsoft Windows may
use Pentium processors.
There are other processors
called Alpha, LSI-11, and
on and on.
Each processor understands only its own mach ine language
Machine language is executed
very
quickly
A mid-range laptop these days has a clock rate of
1.5 Gigahertz.
What that means exactly is hard to explain,
but let’s interpret it as processing 1.5 billion bytes
per second.
Those 12 bytes would execute inside the
computer, then, in 12/1,500,000,000th of a second!
Compiled vs. Interpreted Programs
Applications like Adobe Photoshop and Microsoft
Word are compiled.
This means that they execu te in the computer as
pure machine language.
They execute at
that
level speed.
However, Python, Java, Scheme, and many other
languages are (in many cases) interpreted.
They execute at a slower sp eed.
Why? It’s the dif ference between
translating
instructions and directly
executing
instructions.
Applications are
compiled
Applications like Photoshop and Word are written
in languages like C or C++
These languages are then
compiled
down to
machine language.
That stuff that executes at a rate of 1.5 billion bytes
per second.
Jython programs are interpreted.
Actually, they’re interpreted
twice!
pf3

Partial preview of the text

Download Comparing Compiled and Interpreted Programs: Understanding Computer Speed and Algorithms and more Study notes Computer Science in PDF only on Docsity!

CS1315:

Introduction to

Media Computation

Speed and Complexity Why is Photoshop so much faster?

Today’s class

 Compilation and interpretation  Assembly language  Interpreters  Compilers  Complexity of algorithms  Hardware

Each kind of processor has its own

machine language  Apple computers typically use CPU ( processor) chips called G4 or G5.  Computers running Microsoft Windows may use Pentium processors.  There are other processors called Alpha, LSI-11, and on and on. Each processor understands only its own machine language

Machine language is executed very

quickly  A mid-range laptop these days has a clock rate of 1.5 Gigahertz.  What that means exactly is hard to explain, but let’s interpret it as processing 1.5 billion bytes per second.  Those 12 bytes would execute inside the computer, then, in 12/1,500,000,000th^ of a second! Compiled vs. Interpreted Programs  Applications like Adobe Photoshop and Microsoft Word are compiled.  This means that they execute in the computer as pure machine language.  They execute at that level speed.  However, Python, Java, Scheme, and many other languages are (in many cases) interpreted.  They execute at a slower speed.  Why? It’s the difference between translating instructions and directly executing instructions.

Applications are compiled

 Applications like Photoshop and Word are written in languages like C or C++  These languages are then compiled down to machine language.  That stuff that executes at a rate of 1.5 billion bytes per second.  Jython programs are interpreted.  Actually, they’re interpreted twice!

Why interpret?

 For us, to have a command area.  Compiled languages don where you can print things and try out functions.’t typically have a command area  Interpreted languages help the learner figure out what going on. ’s  For others, to maintain portability.  Java can be compiled to machine language.  In fact, some VMs will actually compile the virtual machine language for you while running—no special compilation needed.  But once you do that, the result can only run on one kind of computer.  Programs for Java (.jar files typically) can be moved from any kind of computer to any other kind of computer and just work.

Java tries to get the best of

both worlds

 Java code is compiled into a machine language (called byte code) for a fictitious machine, the Java Virtual Machine.  Each computer that can execute Java has an interpreter for the Java machine language.  Interpreting Java machine is pretty easy  Takes only a small program  Devices as small as wristwatches can run Java VM interpreters. More than one way to solve a problem  There’s always more than one way to solve a problem.  To go from Architecture to the Student Center you can cut across the parking lot and the field, OR you can walk just on sidewalks  Some solutions are better (faster, shorter, less muddy) than others.  How do you compare them? Finding something in the dictionary  Simple algorithm  Start from the beginning.  Check each page, until you find what you want.  Not very efficient  Best case (you find the word on the first page you check): One step  Worse case (it’s on the last page in the dictionary): n steps where n = number of pages  Average case: n/2 steps

A better search in a sorted list

 Better algorithm  Split the dictionary in the middle.  Is the word you’re at before or after the page you’re looking at?  If after, look from the middle to the end.  If before, look from the start to the middle.  Keep repeating until done or until it couldn’t be there.  More efficient:  Best case: It’s there in the first place you look.  Average and worst case: log n steps The Traveling Salesman Problem  Imagine that you’re a sales person, and you’re responsible for a bunch of different clients.  Let’s say 30—half the size of our optimization problem.  To be efficient, you want to find the shortest path that will let you visit each client exactly once, and not more than once.  Being a smart graduate of CS1315, you decide to write a program to do it.