4 ms·
I have noticed a similar thing recently. A programming challenge with a 10s max time restriction, and just reading the input and storing it in an array takes ov
by sspiff 14y ago
I have noticed a similar thing recently. A programming challenge with a 10s max time restriction, and just reading the input and storing it in an array takes over 7 seconds.
I allocate the array ahead of time, as soon as I know the size.
The equivalent C/C++ version took under a second.
- yxhuvud 14y agoHow did you read the input? All at once or one line at a time?
- sspiff 14y agoOne line at a time. Is that significantly slower for stdin? I would assume that this wouldn't make a difference, since we're talking about simple memory operations, and 20k method invocations shouldn't be that hard on a modern system.
- yxhuvud 14y agostdin? No, that shouldn't matter then, but it would if you were reading from file.