added sampling of RAM during execution in a thread for peak mem usage