It can be handy to time code execution so you know how long things take. However, I find the common way this is done sloppy since it's supposed to have the same indentation, which makes it harder to read what's actually being timed.  long start = System.nanoTime();  // The code you want to time  long end = System.nanoTime(); System.out.printf("That took: %d ms.%n", TimeUnit.NANOSECONDS.toMillis(end - start));   An attempt  I came up with the following, it looks way better, there are a few advantages &amp; disadvantages:  Advantages:   It's clear what's being timed because of the indentation It will automatically print how long something took after code finishes   Disadvantages:   This is not the way AutoClosable is supposed to be used (pretty sure) It creates a new instance of TimeCode which isn't good Variables declared within the try block are not accessible outside of it   It can be used like this:   try (TimeCode t = new TimeCode()) {      // The stuff you want to time  }   The code which makes this possible is:  class TimeCode implements AutoCloseable {      private long startTime;      public TimeCode() {         this.startTime = System.nanoTime();     }      @Override     public void close() throws Exception {         long endTime = System.nanoTime();         System.out.printf("That took: %d ms%n",                 TimeUnit.NANOSECONDS.toMillis(endTime - this.startTime));     }  }   The question  My question is:   Is my method actually as bad as I think it is Is there a better way to time code execution in Java where you can clearly see what's being timed, or will I just have to settle for something like my first code block.
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:
Convert Month Number to Month Name Function in SQL What word indicates spatial data within the geographical and geological domains? In particular, what word is precise enough for a science journal article (i.e., formal prose)? Candidates might include &quot;spatial data,&quot; &quot;geodata,&quot; &quot;geospatial data,&quot; and &quot;geographic data.&quot; &quot;Spatial data&quot; seems too generic (not necessarily within the geographical and geological domains). What is the consensus, if any exists? Prove that for every $a\in A$ $\exists$ $q\in M,s\in A$ s.t. $a=sba+qa$ where $M$ is maximal ideal in $A$. Let A be a commutative ring with unity ring, M be a maximal ideal and $b\notin M$ . Show that there exists $q \in M, s\in A$ such that for every $a \in A$ we have $a=sba+qa$. Show that this is true only when $M$ is a maximal ideal.   Suppose if we take $A=2\mathbb Z$ and $M=4\mathbb Z$, $a=6.$ Then by the given statement $\exists$ $s\in A$, $q\in M$ s.t. $6=6(2s+q)$ $\implies$$s=\frac{1-q}{2}\implies q \text { is odd}$. But $q \in 4\mathbb Z.$  Please someone give some hints. how can solve this.  Thank you.. Objective: To separate text column from figures column in every page I don't know if this has been asked before. But so far nothing has come up with my search.  In some books, the figures are placed at the outer side of the page like in the picture below.    Is this achievable in TeX/LaTeX? That is how does one set up the page so that all text will appear in a 'text column' and the figures appear in a 'figures column' in every page? in the street or on the street This is difficult for me to explain, but how do I put words over a symbol? For instance, I want to add words over an equal sign. Anyone know the command/syntax for that?  Also adding ^ doesn't cut it..., I want the text to appear ON TOP. I want to prove that every real polynomial of odd degree has at least one real root, using  the intermediate value theorem.  Let $P(x) = x^{2n+1} + a_n x^{2n} + . . . + a_0$ for each $a_i \in \mathbb{R}$ and $n \in \mathbb{N}$.  By the fundamental theorem of algebra I know that $P(x)$ has exactly $2n+1$ complex roots, so  $P(x) = (x+r_1)(x+r_2) . . . (x+r_{2n+1})$ for each $r_i \in \mathbb{C}$  I do not know how to complete this but I do know that, at some point, I probably have to show that each root with imaginary part non zero has to come in conjugate pairs, and since $2n+1$ is odd there is at least $1$ root that is imaginary part $0$ and thus real. Jump/Scroll to selected object in the outliner? Is dimensionality reduction almost always useful for classification? What is the shape of a black hole? I was thinking; what shape does a black hole have?. By 'Shape', I mean its form (e.g, circle , cylinder, sphere, torus, etc..).  We usually think of black holes as if they're plugholes (e.g, a flat circular object), but what if they're spherical? A spherical black hole would make much more sense. I would imagine than a black hole shaped like a basketball would be capable of pulling more mass towards it than a flat one, as it has a higher surface-to-volume ratio to do so.  Edit I know that it's probably a sphere, but when you think about it, a cylinder could also be a potential shape. My table is like this:  Sitecode    Month  Amount --------    -----  ------ XX          Jan     1000 XX          Jan     3000 XX          Apr     3000 XX          Apr     1000   What I want is, to show the result something like this:  Sitecode    MonthJAN   MonthAPR --------    --------   -------- XX          4000       4000 Prove that 1/2 + 1/4 + 1/8 ....... = 1 I've often heard that instead of adding up to a little less than one, 1/2 + 1/4 + 1/8... = 1. Is there any way to prove this using equations without using Sigma, or is it just an accepted fact? I need it without Sigma so I can explain it to my little sister.  It is not a duplicate because this one does not use Sigma, and the one marked as duplicate does. I want it to use variables and equations. For many of my datasets I have the same imported data duplicated numerous times, each iteration displaying the data values for a different column (in my case it's fish catch weight per gridded cell per year, so lots of iterations of the same grid, with a different pattern of values per year).  For presentation purposes, it strikes me as helpful to use the same scale for each year, so I go to the original data and divide the maximum value into (arbitrarily) 10 classes and manually input the values and labels after setting the desired colour ramp and input data field:   This is extremely tedious, not just the manual excel calculation part, but also the input interface for the values &amp; labels*, hence my intention to make use of the 'save style' option. HOWEVER: when I save the style as QML and load it for the next layer, it saves everything - including the data field (in my case, year). When I change this field, QGis automatically generates the values &amp; labels based on the data for that field, ditching all of the values &amp; labels I set.   Is there any way to avoid this happening &amp; thereby duplicate class number, values and labels for each field by simply loading a style? (somewhat meta) Am I going around this the wrong way, OR, is there a different face I could use to climb this mountain? Brace expansion not working in a script for i in {1..40} do     echo $i done   I got  {1..40}   and I would like to have something like  1 2 3 and so on   so I can use the variable i inside a command's parameter. I tried this:  find . -type f -size 128 -exec mv {} new_dir/  \;   Which didn't work, and it didn't give me an error. Here is an example of what the file looks like, when using stat -x  $ stat -x ./testfile | grep Size    Size: 128          FileType: Regular File Can I publish an article or thesis about my research without supervisor? Is it possible to set start-up applications to initialize in certain workspaces? I'd like to not have to manually distribute my start-up applications across my numerous workspaces every time I boot up my machine. I'm running Ubuntu 12.04 .  Any Help ? LaTeX baffled by BOM---Unicode's byte order mark. Unicode applies the convention of using a  as signature at the beginning of a text stream, identifying the encoding used within it. The following three bytes at the beginning of a file: EF BB BF, identifies this file as a UTF8 file. Vi and most text editors gracefully ignore this signature. Open office does that as well, but it adds this signature at the beginning.  Now, if I open a TeX file with OpenOffic.org, and I do that quite a lot (for mixed directionality editing), the signature is added, and baffles LaTeX, which produces an error message such as:   ! LaTeX Error: Missing \begin{document}.   See the LaTeX manual or LaTeX Companion for explanation.  Type  H &lt;return&gt;  for immediate help.  ...                                                l.1   ��\documentclass{article}   whereas a simple dump of the file does not show the problem. Is there a way to eliminate this problem, while staying in the realm of latex? My understanding is that GPUs are more efficient for running neural nets, but someone recently suggested to me that GPUs are only needed for the training phase. Once trained, it's actually more efficient to run them on CPUs.  Is this true? Who were the other two heroes with Superman in the newspaper article who left? In Justice League, we see a newspaper article showing three heroes who died (left to their home planets) but it was too fast that I missed catching the faces.   Who were the other two heroes who are dead?