I'm working on some financial analysis software that will need to process large (ish) volumes of data. I'd like to use BigDecimal for the accuracy (some pricing info goes to four or five digits to the right of the decimal) but I was concerned about speed.  I wrote the following test app and it appears that BigDecimal can be 90 to 100 times slower than Doubles. I knew there would be a delta, but that's more than I was expecting. Here's a typical output after many trials.  BigDecimal took 17944 ms Double took 181 ms   Am I missing something?  Here is the code. I tried to make it representative of real world. I created a constant where I could (pi) but also did some inline math of numbers that would vary from data row to data row - such as pi * BigDecimal(i) + BigDecimal(1). My point being that avoiding constructors can't be the only answer.  Fortunately, it appears Double has enough precision anyway since numbers will be typically in the format 00000.00000. Any hidden gotchas I should know about, though? Do people use Double for financial analysis software?  import java.math.BigDecimal  object Stopwatch {     inline fun elapse(f: () -&gt; Unit):Long {         val start = System.currentTimeMillis()         f()         return System.currentTimeMillis() - start     } }   fun tryBigDecimal() {     val arr: MutableList&lt;BigDecimal&gt; = arrayListOf()      for (i in 1..10000000) {         arr.add(BigDecimal(i))     }      val pi = BigDecimal(3.14159)      for (i in 0..arr.size - 1) {         arr[i] = arr[i] * pi / (pi * BigDecimal(i) + BigDecimal(1))     }      //arr.forEachIndexed { i, bigDecimal -&gt;  println("$i, ${bigDecimal.toString()}")} }  fun tryDouble() {     val arr: MutableList&lt;Double&gt; = arrayListOf()      for (i in 1..10000000) {         arr.add(i.toDouble())     }      val pi = 3.14159      for (i in 0..arr.size - 1) {         arr[i] = arr[i] * pi / (pi * i + 1)     }      //arr.forEachIndexed { i, bigDecimal -&gt;  println("$i, ${bigDecimal.toString()}")}  }  fun main(args: Array&lt;String&gt;) {     val bigdecimalTime = Stopwatch.elapse(::tryBigDecimal)     println("BigDecimal took $bigdecimalTime ms")      val doubleTime = Stopwatch.elapse(::tryDouble)     println("Double took $doubleTime ms") }
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:
Exporting feature class into multiple feature classes based on field values using ArcGIS Desktop? I have a feature class with over 2,000 features, and I need to make them all individual feature classes based on a field.   Is there a way to do this? I am doing some homework exercises and stumbled upon this question. I don't know where to start.      Prove that the union of countably many countable sets is countable.   Just reading it confuses me.   Any hints or help is greatly appreciated! Cheers! Isn't every subset of a compact space compact? Let $\mathfrak{C}$ be an open cover of a topological compact space $X$, and let $\mathfrak{B}\subseteq \mathfrak{C}$ be its finite subcover. Then every subset of $X$ also has the same cover and subcover! Shouldn't every such subset also be compact then?  Motivation: I read somewhere that every closed subset of a compact space is compact. I wonder why it shouldn't be the case for every subset of $X$, rather than just the closed ones. A coin is tossed three times: The probability of zero heads is 1/8 and the probability of zero tails is 1/8.  And my question is: What is the probability that all three tosses result in the same outcome?   So, if P(zero heads)= 1/8 , then that should be the same of p(all tails)?  If so, we could use the Addition Rule which is $P(A \cup B) = P(A) + P(B)$  where A and B are disjoint events, i.e. $A \cap B = \emptyset$, A is the event of tossing all heads and B is the event of tossing all tails.  I'm not sure how to continue after that... would the complement be used? Evaluation of $\int_{-\infty}^\infty \frac{\sin(at)}t\ dt$ I just need to know if this integral converges.  If it does, what is the value?  If not can anyone tell me what is the value of the $$ \int_{-\infty}^\infty 2\,\frac{\cos(w)\sin(w)}{w}\ dw ? $$ Why can charges outside be ignored in Gauss's Law? In MIT's 8.02 course, it is shown in lecture 3 that we can derive Gauss's Law from Coulomb's to get  $ \phi = \oint \vec{E} \cdot \vec{dA} = \frac{Q_{enc}}{\epsilon_{0}} $  However, in the lecture, it was assumed that there were no charges outside the surface. Later, Gauss's Law was used and the charges outside the sphere were ignored.  I've been thinking about it and came across .  The first answer by user levitopher helped a bit. I think that the lecture's argument still holds when there are charges outside because $ \vec{E} $ is added vectorially.  Suppose we have $ Q_{enc} $ in a sphere and $ Q_{out} $ outside the sphere. Then,  By definition, $ \phi = \oint (\vec{E_{Q_{enc}}} + \vec{E_{Q_{out}}}) \cdot \vec{dA} $ $ = \oint \vec{E_{Q_{enc}}} \cdot \vec{dA} + \oint \vec{E_{Q_{out}}} \cdot \vec{dA}$ $ = \oint \vec{E_{Q_{enc}}} \cdot \vec{dA} + 0 $ $ = \frac{Q_{enc}}{\epsilon_{0}} $  This assumes that $ \oint \vec{E_{Q_{out}}} \cdot \vec{dA} = 0 $ because any field lines that go in must come out (hand wavy but I'm just going to accept it for now).  I'd just like to know if this argument is sound. Why were there so many spells cast in the movies without saying the words to the spell? From my memory of the last Harry Potter movie I saw, I've seen many wizards cast spells without saying the spell at all.  During the final battle in Hogwarts, many wizards just swung their wands and their enemies were knocked out. I am 100% sure about this!  The most remarkable spells were the ones that emit a green or red beam in the final battle of Harry Potter against Voldemort when they pushed their beams towards each other.  So, the question is, are they cheating? Because, unless there are wordless spells, they must say the words for a spell. Understanding the impact/risk of turning off "verify backup integrity" on SQL backup Currently we use standard maintenance plans for backups on the SQL Server 2005/2008/2008R2/2012 servers in our environment, and the "Verify backup integrity" box has always been checked.  Some of the backups run very long, so I've recommended turning off that option, but management needs me to document the impact and risks of this change.  I understand the use and history of this option, it just seems unnecessary to me to double the time for the backup job when (in my opinion), any error that is likely to occur would occur during the backup step, not during the verify.  Am I wrong? Is it minimal risk to turn this off, if I am backing up to disk and not to streaming tape or something? (We back up over the network to an EMC DD-800 backup appliance, if that is relevant.)  Is there any official MS recommendations for when it is safe to turn this off?   Do you run "verify" on every backup in your environment? Do you spot-check them?  EDIT: To clarify, when you check "verify backup integrity" in the maintenance plan, SQL will do a full RESTORE VERIFYONLY on each database immediately after each backup. This is just as data/IO intensive as the original backup, and (basically) doubles the overall time of the backup job. This is not the same as enabling the "checksum" option on backup (which can't be done in the wizard, as far as I know). My competitor is using Alexa to see what I am doing. I need to get stop Alexa from including my sites in their rankings. How can I do so?   Is it possible to deny access to any visitor with the Alexa toolbar and deny access to Alexa bot requests? Are layer files compatible between ArcGIS 10 and 9.3? If I save layer files in ArcGIS 10, can they be opened and modified in ArcGIS 9.3? $(a_n+a_{n+1})$ is convergent implies $(a_n/n)$ converges to $0$ Let $(a_n)$ be a sequence such that $(a_n+a_{n+1})$ is convergent. Prove that $(a_n/n)$ converges to $0$.   $(a_n+a_{n+1})$ convergent to $L$ means that for all $\epsilon$, there exists $N$ such that for all $n\geq N$, $|L-a_n-a_{n+1}|&lt;\epsilon$, or in other words $L-\epsilon&lt;a_n+a_{n+1}&lt;L+\epsilon$. How to proceed from here? SSMS wont give up file associations Show that every uncountable set of real numbers has a point of accumulation. Did all Headmasters get a portrait in Hogwarts? Throughout the Harry Potter series, we see that deceased Headmasters of the school get a semi-sentient portrait of themselves in the Headmaster's Office, at the service of the current Headmaster. Do all Headmasters get a portrait? What are the conditions of getting one? For instance, there are a couple of times when Dumbledore is temporarily deposed as Headmaster: Dolores Umbridge takes over the job in Order of the Phoenix, and Minerva McGonagall takes the job in Chamber of Secrets and Half Blood Prince. Will Umbridge and McGonagall have portraits in the Headmaster's Office when they expire? Find the value of $x,y$ for the equation $12x+5y=7$ using number theory . I tried the solution using other ways like:  $12x+5y=7$  $12x=7-5y$  $x=7-5y/12$  putting the value of $x$  $12(7-5y/12)+5y=7$  both $12$ will cancel out  $7-5y+5y=7$ here comes the problem please help me ? How to change plot style or other options after it was created Google isn't surfacing Events rich snippets in SERP when JSON-LD Structured Data is valid Google confirms our site has thousands of valid MusicEvent structured data objects presented using JSON-LD, as indicated in the Structured Data section of Webmaster Tools. However, rich snippets for the events do not show up in any search result pages. The Rich Cards tab in Webmaster Tools says:     We did not find any structured data for rich cards on your website.   The structured data is valid with no errors in the Structured Data Testing Tool. We do generate some warnings occasionally for missing endDate and price fields. Comparing our code to a survey of other sites whose rich snippets do appear, we are not doing anything unique in terms of our markup.  The data has been there for months, in fact over the months we've tried also using Microdata format. The Structured Data section indicates that many pages were crawled this week.  Besides SDTT validation, what else can I check to troubleshoot this issue? When is "seems to be" used instead of "seems"? The baby seems happy/comfortable. The baby seems to be happy/comfortable.   Are these both correct? If both are correct, what are the differences between them? Is it possible to call a non-exported function that resides in an exe? For $x\in\mathbb R\setminus\mathbb Q$, the set $\{nx-\lfloor nx\rfloor: n\in \mathbb{N}\}$ is dense on $[0,1)$