Removing $display statements gives a dramatic improvement in runtime.