Encode optimization

Run in command line the new script "simple_test_speed.php" to see the
improvements.