Last active
March 28, 2024 00:15
-
-
Save ppazos/24ff5458f48771aba4d5ef34a28f15bc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def lines = (1..10000000) | |
println lines.getClass() | |
// with list.each {} | |
def start = System.nanoTime() | |
lines.each { line-> | |
line++; | |
} | |
println ((System.nanoTime() - start) / 1_000_000_000) | |
// with loop over list | |
start = System.nanoTime() | |
for (line in lines){ | |
line++; | |
} | |
println ((System.nanoTime() - start) / 1_000_000_000) | |
// fastest loop | |
start = System.nanoTime() | |
for (int line: lines){ | |
line++; | |
} | |
println ((System.nanoTime() - start) / 1_000_000_000) | |
start = System.nanoTime() | |
lines.forEach (line -> { | |
line++; | |
}) | |
println ((System.nanoTime() - start) / 1_000_000_000) | |
start = System.nanoTime() | |
for (int i=0; i<lines.size(); i++){ | |
lines.get(i)++; | |
} | |
println ((System.nanoTime() - start) / 1_000_000_000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment