arduino code works slower than arduino code generated by ldmicro

Also by using direct port manipulation Arduino Reference - Arduino Reference

you can read and write pins about 5x faster than with the pre-safed Arduino functions.
Pin safety is up to you then, take care if/when changing modes and access like when running a switch matrix.