It depends on when you next need to use the system. If it is immediately after the memory hogging code exits, there's probably not much of a win.
But if you run the memory hogging program, then go to lunch, if the swapoff/swapon is triggered before you get back, you will be avoiding the delays entirely.