Perhaps you are benchmarking the cost of 5 function calls vs 1 ?
Hi Dave,[Resending as for some reason my previous message has been deleted]
On Tuesday, February 25, 2014 11:41:57 PM UTC-5, Dave Cheney wrote:Perhaps you are benchmarking the cost of 5 function calls vs 1 ?
So you are saying the 10x difference is caused by calling math.Pow 4 times hence function call overhead? I'm not trying to imply something but isn't that a lot?
In my specific case not calling math.Pow decreased the the total runtime from ~5 min to well under 3 min for a complete graph with 65356 vertices and 2135670690 edges.I checked the go build output by passing -gcflags -m and it does not mention anything about the Euclidean function, is this because go cannot inline non-leaf functions (if my terminology correct)?
--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/GOviOxfkt2E/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
There you go. I was completely wrong, not unexpected.So the real cause is no fast path for x^2.I recommend doing the following (in order)
2. if you want to, propose a change with your fix. If Pow(x, 2) doesn't have a test case you will need to add one, as well as including a benchmark if the benchmarks in the math package don't already cover this.
Hi Dave,
On Wednesday, February 26, 2014 12:35:05 AM UTC-5, Dave Cheney wrote:There you go. I was completely wrong, not unexpected.So the real cause is no fast path for x^2.I recommend doing the following (in order)Been there, done that :)1. raise an issue, golang.org/issue/new linking to this discussion and your diagnosis.Will do in a minute.2. if you want to, propose a change with your fix. If Pow(x, 2) doesn't have a test case you will need to add one, as well as including a benchmark if the benchmarks in the math package don't already cover this.I think I would like to see people's reaction first before proposing a solution with test cases and benchmarks. I fear that others would object this idea given the fact that it's not possible to add every special case into Pow function's fast path (Eg; this change fixed the Pow(N, 2) but Pow(N, 3) suffers with they same symptom). Maybe one could argue that it's OK to add special cases for 2 and 3 by assuming they will be used more frequently.
n*n = n^2n^2*n = n^3n^3*n^3 = n^6n^6*n^6 = n^12n^12*n^3 = n^15
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
Paraphrasing Michael Jones (in another discussion): Generally, using a general tool (Pow, which works for all real exponents) when all you really want is x**2, is very expensive.
--
On Tuesday, February 25, 2014 11:41:57 PM UTC-5, Dave Cheney wrote:
Perhaps you are benchmarking the cost of 5 function calls vs 1 ?
So are you saying the ~10x difference is caused by calling the math.Pow 4 times and hence function call overhead? I'm not trying to imply something but isn't that sounds a lot. In my specific case not using math.Pow decreases my the total runtime from ~5min to well under 3min for a complete graph with 65356 vertices and 2135670690 edges.Also, passing "-gcflags -m" to go build shows nothing about the Euclidean function. Is it because go cannot inline non-leaf functions (if my terminology correct)?
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
Actually, there are no fast paths in the special cases of Pow. It may look like there is one for Pow(x, 0.5), but it's not. The IEEE 754 standard says that Sqrt(-0.0) = -0.0, so Pow(-0.0, 0.5) does, too.
"Binary Powering"
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
Function call overhead is non-zero. Doing a floating-point multiply is fast. So several functions calls, each of which has to navigate the switch table (if/else if/else if/...) and then do the multiply, is going to be slower. If your program is dominated by the computation, then yes, 10x is very possible. As has been stated by others, Pow(x,y) is capable of Pow(Pi,E) and all you want is X*X, so just compute X*X. (Depending on the larger algorithm, you might get away without the sqrt too --- if all you need is to order based on sqrt then ordering on the square of that will give you the same order.)
Well, for example, Pow(±0, ±0) = 1 (not 0), Pow(NaN, ±0) = 1 (not NaN), and Pow(-0, 1) = -0 (not 0). The IEEE 754 standard defines these values, which have changed from time to time.