I have a program written in Scala. I wanted to measure the execution time of different independent code blocks. When I did it in the obvious way (i.e. inserting System.nanoTime() before and after each block), I observed that the the execution time depends on the ordering of the blocks. The first some blocks always took more time than the others.  I created a minimalistic example that reproduces this behaviour. All code blocks are the same and call hashCode() for an array of integers, for simplicity.  package experiments  import scala.util.Random  /**   * Measuring execution time of a code block   *   * Minimalistic example   */ object CodeBlockMeasurement {    def main(args: Array[String]): Unit = {     val numRecords = args(0).toInt     // number of independent measurements     val iterations = args(1).toInt      // Changes results a little bit, but not too much     // val records2 = Array.fill[Int](1)(0)     // records2.foreach(x =&gt; {})      for (_ &lt;- 1 to iterations) {       measure(numRecords)     }   }    def measure(numRecords: Int): Unit = {     // using a new array every time     val records = Array.fill[Int](numRecords)(new Random().nextInt())     // block of code to be measured     def doSomething(): Unit = {       records.foreach(k =&gt; k.hashCode())     }     // measure execution time of the code-block     elapsedTime(doSomething(), "HashCodeExperiment")   }    def elapsedTime(block: =&gt; Unit, name: String): Unit = {     val t0 = System.nanoTime()     val result = block     val t1 = System.nanoTime()     // print out elapsed time in milliseconds     println(s"$name took ${(t1 - t0).toDouble / 1000000} ms")   } }   After running the program with numRecords = 100000 and iterations = 10, my console looks like this:     HashCodeExperiment took 14.630283 ms   HashCodeExperiment took 7.125693 ms   HashCodeExperiment took 0.368151 ms   HashCodeExperiment took 0.431628 ms   HashCodeExperiment took 0.086455 ms   HashCodeExperiment took 0.056458 ms   HashCodeExperiment took 0.055138 ms   HashCodeExperiment took 0.062997 ms   HashCodeExperiment took 0.063736 ms   HashCodeExperiment took 0.056682 ms   Can somebody explain why is that? Shouldn't all be the same? Which is the real execution time?  Thanks a lot, Peter     Environment parameters:   OS: ubuntu 14.04 LTS (64 bit)   IDE: IntelliJ IDEA 2016.1.1 (IU-145.597)   Scala: 2.11.7
How do you write (and run) a correct micro-benchmark in Java?  I'm looking for some code samples and comments illustrating various things to think about.  Example: Should the benchmark measure time/iteration or iterations/time, and why?  Related:
How does one attack a two-time pad (i.e. one time pad with key reuse)? My question might appear the same as the question , but actually I did read all the answers and none of them helped me with the details I need.  I am new to cryptography and my problem is with two time pad attacks on OTP. The problem I had in my course was that I have 10 ciphertexts encrypted with the same key $K$. I am then given another ciphertext that I should decrypt.  I know that XOR-ing two ciphers gives me the XOR of their original messages.  My question is what is the correct thing to do after that?  I tried to take 3 ciphertexts $C_1, C_2$ and $C_3$.  Then get $S_1 = C_1 \oplus C_2  \oplus $' ', also get $S_2 = C_1 \oplus C_3 \oplus$ ' '.  After that I compared all corresponding characters in $S_1$ and $S_2$,  and if $S_1[i] = S_2[i]$ then I calculate $S_1[i] \oplus C_2[i]$ to get $K[i]$.  I tried this on paper before coding and it worked, but I might be missing something.  Is this the right approach? Why does it work? Space ship manned by only AI returns home to a different earth, back in time Problems with partial derivatives. Fourier Series for $|\cos(x)|$ Cannot find Background Images feature to add in a photo in Blender 2.8  Where is it? How to remove feeds from WordPress totally? I want to completely remove feeds from WordPress. I am using this little function from    /** * disable feed */ function fb_disable_feed() { wp_die( __('No feed available,please visit our &lt;a href="'. get_bloginfo('url') .'"&gt;homepage&lt;/a&gt;!') ); } add_action('do_feed', 'fb_disable_feed', 1); add_action('do_feed_rdf', 'fb_disable_feed', 1); add_action('do_feed_rss', 'fb_disable_feed', 1); add_action('do_feed_rss2', 'fb_disable_feed', 1); add_action('do_feed_atom', 'fb_disable_feed', 1);   Still there is tons of transient options.. like _transient_feed_mod or _transient_timeout_feed_mod  How can i completely remove feeds from WordPress? Are Playstation 4 games locked to a certain region? This question has been asked before, but it was for PS3 and Xbox 360 and was asked August 2010. This time around my question goes specifically to PS4, since I'm moving from Mexico to Europe and I was wondering if the European games will run in my console or if I'll have to buy a new one. I never thought of this before (which is why I never paid attention if it was mentioned in reports or specs of the console) and the research I did wasn't too helpful. Show that if $a$ has order $3\bmod p$ then $a+1$ has order $6\bmod p$. Show that if $a$ has order $3\bmod p$ then $a+1$  has order $6\bmod p$. I know I am supposed to use primitive roots but I think this is where I am getting caught up. The definition of primitive root is "if $a$ is a least residue and the order of $a\bmod p$ is $\phi(m)$ then $a$ is a primitive root of $m$. But I really am not sure how to use this to my advantage in solving anything.  Thanks! Inspired by  I was wondering why the Half Blood Prince left his book as a class copy. One would think that it was precious to him, since he invested so much in it. He made up potions and spells up by his own. I would expect him to keep it to himself. Both, because of the personal value of it, and to prevent others to (as happened at last) use his work (misguided and/or against him).  Is there any canon explanation why his book was left as class copy? freezing header in a table in html Check if the application is already installed Is an expanding map on a compact metric space continuous? SQL Server nvarchar(max) vs nvarchar(n) affects performance How to programmatically click a button in WPF? “Are” vs. “is” after “parents and the family” How to show the inequality for $\int_{0}^{\pi/4}\tan^n(x) dx$ I can't seem to figure out the inequality option, I substituted n=2 for the answer bit is there any elegant way of getting it? There are many lengths in LaTeX. For instance, \enskip, \enspace, \quad, \parskip, \smallskip, ...  Some of them are mostly used for vertical spacing, some others are mostly used for horizontal spacing, and perhaps some of them are used in both cases. I wonder whether there is a list that indicates the meaning and intended use of each length in LaTeX.  By "intended use" I mean not only whether the length is vertical or horizontal, but in which circumstances it is a good practice to use that specific length. Command with percent symbols not running in crontab The following crontab does not work:  # TEST LINE DOES DOT RUN */1 * * * * /bin/echo 'test '`/bin/date +%Y-%m-%d` &gt;&gt; /tmp/test   I also tried starting it with:  SHELL=/bin/bash   Update: I thought the backtick characters ` were the villains, but as the answer below clarifies the percentage % was the culprit! Book where girl can grow nails and might be a thief I'll apologize for this being a vague description up front. I read a book about 8 years ago about a girl who could grow her nails into essentially razorblades or long enough that they could be used as razors. She travels to a city and either becomes an assassin or a thief (pretty sure it was a thief). I vaguely remember the book opening with her being chased by a mob. At some point during her thief training she realizes that the layout of the city is the key to some important plot device. I think she was given some scroll or cryptic image and then during her training she realizes that the layout of the city correlates to it.  Although I did read this 8 years ago I'm pretty sure the book was at least 5-10 years older than that, maybe even more because it was my mom who gave it to me and she said had read it when she was younger. The dust cover was missing when I read it so I have no description for the cover. I do remember that the author was male. It was a fantasy setting and there may have been vampires involved at some point but that part of my recollection of the book is even fuzzier than what I've already described. I've tried googling for this book but obviously my description is fairly vague. I will gladly answer any follow up questions that I can to try and help figure this out because it has been bothering me for years. 1) Up until now, during practical work sessions, I always used these formulas for uncertainty propagation:  if $C = A+B$  or  $C = A-B$ $$\Delta C = \Delta A + \Delta B$$ if $C = AB$ or $C = \frac{A}{B}$ $$\frac{\Delta C}{C} = \frac{\Delta A}{A}  + \frac{\Delta B}{B}$$ if $C = A^m$ $$\frac{\Delta C}{C} = |m|\frac{\Delta A}{A}$$   These formulas are derived from the expression for the differential of a function of multiple variables:  if $C = f(A,B)$ $$ dC = \frac{\partial C}{\partial A}dA + \frac{\partial C}{\partial B}dB \Rightarrow \Delta C = \frac{\partial C}{\partial A}\Delta A + \frac{\partial C}{\partial B}\Delta B$$  and I think that makes sense because the value C is just a function of two variables that happen to be measurements.  2) But this morning, I was told that this is wrong and I should actually use these instead:  if $C = A+B$  or  $C = A-B$ $$(\Delta C)^2 = (\Delta A)^2 + (\Delta B)^2$$ if $C = AB$ or $C = \frac{A}{B}$ $$\left(\frac{\Delta C}{C}\right)^2 = \left(\frac{\Delta A}{A}\right)^2  + \left(\frac{\Delta B}{B}\right)^2$$  which are apparently derived from a general formula:  $$(\Delta C)^2  = \left(\frac{\partial C}{\partial x_1}\Delta x_1\right)^2 + \left(\frac{\partial C}{\partial x_2}\Delta x_2\right)^2 +   \hspace{0.3cm}...$$  or   $$\Delta C  = \sqrt{\left(\frac{\partial C}{\partial x_1}\Delta x_1\right)^2 + \left(\frac{\partial C}{\partial x_2}\Delta x_2\right)^2 +   \hspace{0.3cm}...}$$  3) So:   Why is this formula better?  Where does it come from? What does it actually represent? (Do I recognize the shape of a norm in that last formula?)  What is wrong with the formula of the differential?   I'm asking a lot, but the propagation of uncertainty always confused the ship out of me.