Performance of nested Loop in Go - Getting Help

Real quick I was just teasing, reading my post it came across snarky but I just found the thread amusing. So I get what you're communicating, I think? But what you said is:

I tried to replicate the same logic as the OP in Java at: http://pastebin.com/Zbp4gAiN

I laughed because I visited the pate bin and the program was not an identical java program. The java version had no if statement to do sorting, not to mention it was made using a sorted index. Point is you did the same thing as the OP, made 2 programs, talked about the differences, then posted only 1, which was different then the OPS program. Lol.

You took ops rudimentary sort algorithm and turned it into some kind of ugh, two-pass array reverse. The way you are going about this array reverse is really hard for Go to bounds check, assuming you did the identical program it would have several issues. First as you suspected it would certainly evade bounds check elimination in this form, even if you initialized a array rather than a slice I'm pretty sure you will have 2 calls to runtime.panicindex() I imagine.. something that the JIT's more sophisticated hot-spot analysis may pick up on after the first iteration. But there is a lot of needless instructions that the JVM may not have to perform.. there is what 11 movq's in that loop.

I'm not sure what the JVM is able to reduce that loop too. I do know for a fact though if you used a proper array reverse it would rip through that array in around 50-100us? Not typing that on my phone, but theirs a example on the slicetricks golang wiki page. Point is whatever the JVM is doing to squeeze out 2x speedup of a shitty algorithm isn't worth investigating to me when properly implementing it gave me 7 orders of magnitude. It can be interesting sometimes, but I don't think in practice any of the performance stuff ever really matters. It's far more often I see poor use of an algorithm then Go missing some bleeding edge SSA optimization pass / pipeline. But yea, to clarify it's interesting and I think it's cool you tested it, don't want to come across like a grumpy dick or anything.. hehe. Maybe if you get bored you can dump the Go asm and read java's diagnostics outputs / asm and see the hotspot data for that loop. Have a good one man.

/r/golang Thread Parent Link - forum.golangbridge.org