You are on page 1of 1

CSC 190 Report 1

Dongbin Lee 999708124 - Yinghui Fan 999594648 January 21, 2013 1. Python vs. C Python: 0.007u 0.004s 0:00.01 0.0% 0+0k 0+0io 0pf+0w C: 0.000u 0.000s 0:00.00 0.0% 0+0k 0+0io 0pf+0w 1. C was much faster than python. The user time, and the system time shows that it took mean_temps.py much longer to execute than mean_temps.c. 2. Python was slower because it needed to load an interpreter. Unlike Python, C uses a compiler. Compiling takes two steps but it will lead to a much faster run time. This is because compiler will generate an executable program that will run similar to other applications on the machine. 3. There was a difference in the "user time" and "system time" for the two. C had a much faster user time and system time because it took less than 0.000 seconds to set up the program and 0.000 seconds to actually run it. C code ran faster because the code has already been compiled using the compiler and turned into machine code. Python's code takes much longer because it has to load the interpreter, then go through the intermediate stage, be turned into a low level language such as C, and then it can finally be turned into machine code for it to run. 2. Matlab vs. C 1. Yes, there was a difference between the two C programs. The file array_traversal_row.c had a much faster run time then the array_traversal_col.c. This is because C programming languages uses a row major ordering system where the rows are stored one after the other [1]. 2. Yes, there was a difference between the two Matlab programs. The file array_traversal_col.m had a bit faster run time than the array_traversal_row.m. This is because matlab uses column-major ordering system [1]. 3. C was faster than Matlab because just like python, Matlab also uses an interpreter. Unlike Matlab, C can create files that run similarly to the other applications on the system.

Columnmajor traversal (ms) Row- major traversal (ms)

C code 0.048u 0.008s 0:00.05 80.0% 0+0k 0+0io 0pf+0w 0.018u 0.006s 0:00.02 50.0% 0+0k 0+0io 0pf+0w

Matlab code 3.640u 0.209s 0:04.67 82.2% 0+0k 0+0io 0pf+0w 3.696u 0.215s 0:04.74 82.2% 0+0k 0+0io 0pf+0w

3. Benford's Law 1. Yes, the distributions we looked at does follow Benford's Law. According to this law, the number 1 occurs as the first digit about 30% of the time and then as the numbers get higher, it occurs less frequently [2]. 2. It is easy to tell because the frequency reduces as the value of the digit gets higher. Which means the number 1 occurs as the first digit the most and the number 9 occurs as the first digit the least [2]. This means that the probability will decrease as the value increases from 1 to 9. Therefore, the distributions created by the numbers.c program, follows Benford's Law. 3. Here is a graph of the distribution [3]:

The graph shows a very strong relationship with the results from the numbers.c file. References [1] "Row-major order." Internet: http://en.wikipedia.org/wiki/Row-major_order, December 22, 2012 [January 22, 2013] [2] Weisstein, Eric W. "Benford's Law." Internet: http://mathworld.wolfram.com/BenfordsLaw.html, [January 20, 2013]. [3] John Walthoe. "Looking out for number one" Internet: http://plus.maths.org/content/looking-outnumber-one, August 31, 1999 [January 20, 2013].

You might also like