I have a method with nested loops like below inside which I do some computationally expensive stuff and some computationally cheap stuff:
for(int i = 0; i < SIZE_I; ++i) {
// Do cheap stuff 1
// Do computationally expensive stuff 1
for(int j = 0; j < SIZE_J; ++j) {
// Do cheap stuff 2
// Do computationally expensive stuff 2
for(int k = 0; k < SIZE_K; ++k) {
// Do cheap stuff 3
// Do computationally expensive stuff 3
}
}
}
Currently, I call my method once. But I need to separate my cheap stuff from my expensive stuff. The problem is that if I develop two methods, I will need to repeat the nested loops and lots of code tangled with them.
I wonder if there is a best practice or tool to help me break my single method into two methods without repeating a whole lot of code. Or maybe if there is a solution to separate the cheap from the expensive without the need to break down my single method into two methods?