Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Very glad you succeeded but for the future don't post issue before you are quite sure of your program:-) You can simply post a "Question". You can label your post with "Issue", "Question" or "Suggestion". BTW thanks for your last feedback!
Lots of guys passed the tests in C#. I just tried a few solutions and everything worked fine. The tests are waiting for a pair or null; here it says you that you failed at index 0 of an array.
Please if you fail a test could you post the complete result of this test with the input and your output?
That's interesting! I'm afraid we're entering engine-specific optimization territory, though.
Specifying the array dimensions is generally accepted as a hint for the compiler. It may or may not optimize for it. It doesn't mean it'll pre-allocate anything. It's also highly dependent on the later usage of the array. In my system, Safari used it for some slight advantage on your jsperf, while Chrome didn't.
It's "hard" to implement the "fastest" version of an algorithm in js. Each engine has its own optimizations and, on top of that, each one of them keeps updating their speed-focused tweaks, often rendering previous hacks slower than naive implementations.
Chrome did account for it on smaller arrays, though (I'm not sure what kind of buffer you speak of, but even when making several arrays with random data while storing their references and later making use of them, it proved faster on my system). Last time I checked it'd use actual underlying arrays when possible. Perhaps 1m is too big for some of those optimizations? Perhaps using sparse arrays is actually faster than allocating 1m-indexes arrays? I don't know.
I guess what I meant to say is that, semantically, it is a hint for optimization. But you are in the hands of the current optimizer.
I'd certainly enjoy reading some actual info on the optimization techniques being used in these cases on the current js engines.
http://jsperf.com/array-preallocated-vs-pushed/3
There isn't much of a difference between pre-allocated and unallocated if you are using push() to grow the array. Preallocation does significantly improve performance if you use direct assignment to grow the array e.g.
myArry[1] == x;
.Edit: Changed the old jsperf that I found to have larger arrays to ensure any sort of internal buffer built by the JIT is exceeded.
This comment is hidden because it contains spoiler information about the solution