mergefiles: add profiling code. minor perf optimization