Topic List | Page List: 1 |
---|---|
Topic | Isn't this the fastest way to do a for loop |
Sahuagin 02/07/20 2:32:44 AM #2: | readability is more important than typing slightly less. a rule of thumb is to never use ++, especially combining it with evaluation. for (int x = 0; x < length; x += 1) { } one exception I allow myself is when you have a list of array accesses that all reference sequentially. var x = -1; Object.Property = values[++x]; Object.AnotherProperty = values[++x]; // etc... it's less error prone not to actually type sequential integers. can also use a closure: var x = -1; Something next() => values[++x]; Object.Property = next(); Object.AnotherProperty = next(); (there's also a reason why I use ++x instead of x++ but can't remember.) Yellow posted... Doing it this way basically removes an opcode from every loop, right?I don't think so, how could it? what opcode would be removed? always going to be something like: mov ax, 0 loop: cmp ax, length jl done <body> inc ax jmp loop done: might be able to eliminate a jump moving things around but I think that's the order things occur with a for loop. --- ... Copied to Clipboard! |
Topic List | Page List: 1 |