210 likes | 381 Views
Data-Structure and Algorithm. Fall 2003 Project 1. Outline. Goal Mandatory Experiments How to run experiments in Java in C/C++ How to measure the running time in JAVA in C/C++ Tips Grade. Goals. Implement the four MSS algorithms Measure the running time Analyze the result !
E N D
Data-Structure and Algorithm Fall 2003 Project 1
Outline • Goal • Mandatory Experiments • How to run experiments • in Java • in C/C++ • How to measure the running time • in JAVA • in C/C++ • Tips • Grade
Goals • Implement the four MSS algorithms • Measure the running time • Analyze the result ! • Does the big-O notation work? • If not, analyze why! • Experience the power of optimization • In various languages (JAVA, C, C++)
Mandatory Experiments • Implement four MSS(max subsequence sum) algorithms in textbook • in C/C++ • in Java • Run experiments on four different environment on same machine.
How to run experiments in Java(1/2) • Just compile .java file with javac. • Then run .class file with java in Interpreter mode and JIT (HotSpot) mode. • JVM(Java Virtual Machine) • Optimization occurred at runtime • Interpreter mode : no optimization • JIT mode (HotSpot) : optimization at runtime • You can find out how to change this mode by command line option at java.sun.com for SUN JDK.
How to run experiments in Java(2/2) • For more information, visit • http://java.sun.com/docs/ • And follow links • “SDK Docs” of your JDK version • -> ”SDK Tool Documentation” • ->”java” • For example, if you use JDK 1.4.1, you may find doc at • http://java.sun.com/j2se/1.4.1/docs/tooldocs/windows/java.html
How to run experiments in C/C++(1/2) • For C/C++, optimization occurred at compile time. • Compile C/C++ source file with your favorite C/C++ compiler. • w/o optimization option • with optimization options • Then run executable file. • You can find out how to disable/enable optimizations within help documents included in your C/C++ compiler.
How to run experiments in C/C++(2/3) • In case of GCC, • You can select the optimizing level with • Compile flags : –O1, -O2, -O3 • You can find other many optimization options by • gcc --help
How to run experiments in C/C++(3/3) • MS Visual C++ • You can select the optimizing level at • Project -> Settings -> C/C++ -> Optimizations • Set Optimization with Maximum Speed (You’ll see the /O2 option appearing in the project option textbox) • You can find other many optimization options in help or by just typing below command in command window. • C:\Program Files\Microsoft Visual Studio\VC98\Bin> cl /?
How to Measure the Running Time in JAVA • Using java.lang.System.currentTimeMillis() • Returns the current time in milliseconds in long type. • Usage import java.lang.*; … { long start_time, end_time, elapsed_time_in_msec; start_time = System.currentTimeMillis(); { run (); } end_time = System.currentTimeMillis(); elapsed_time_in_msec = end_time – start_time; }
How to Measure the Running Time in C/C++ (1/2) • Using clock() or time() in time.h or gettimeofday() • Because resolution of above functions is dependent on platform(OS/CPU) and compiler, you have to select it at your own risk. • You can find out about clock() and time() at below website. • http://www.gnu.org/manual/glibc-2.2.3/html_chapter/libc_21.html#SEC425
Tips (1) – Exclude I/O time and.. And exclude initializing phases.
Tips (2) – Garbage Collector in JVM • GC impact upon running time. • GC(Garbage Collector) is unexpectedly called during the execution, so the impact on running time should be inspected. • One method to reduce this effect is • By increasing initial heap size of JVM by command line option, you can prevent invocation of GC
Tip (3) – other factors.. • OS(Operating System) • You had better stop all unnecessary services and applications. • Cache Misses • Cache misses greatly affects your application’s running time. • I’m not sure you can reduce this effect, but just consider this when analyzing results. • And many other thing can affect running time. Find it yourself!
You have to submit..(1/3) • Report only! • No source code required in report! • In Report, • Describe specification of your experimental environment • CPU, clock speed, cache information(L1,L2) • OS, Compiler, JDK
You have to submit..(2/3) • In Report, • Explain which method you use to measure running time. i.e. clock(), time(), gettimeofday() or other method.And explain why! • Explain which options you used and how do you run experiments. And explain why! • Show experimental result of four algorithm in four different experimental environment.(16 results!) • Use graphical representation! • e.g. Graphs, Diagrams
You have to submit..(3/3) • In report, • Then analyze the result. This is most important! • Does Big-O notation work? • If not, why? • Does optimizations affect running time? • Comparison between w/o opt and w/ opt. • Does any other factor affect running time? • Conclusion! • Your opinion on performance and Big-O notation in real world.
Grade (just for this project) • Explain your experiments in detail? • But you don’t have to explain MSS algorithm! • Explain your experimental result logically? • Correctness of experimental result may be not considered. • Bunch of useless data is negative factor! • Let TA grade your report efficiently :) • If you have done more experiments and find out more, you may get additional point.
Contact Information • TA • Email : dna_ta@altair.snu.ac.kr • Office : Bld. 301 Rm. 851 • If you have any question, plz use bulletin board at homepage. • Submit • Due date : will be announced on homepage • Place : Assignment box at Bld. 301 Rm. 851