Quote:
after my tests i found that save it as jpg file on disk is faster then on memory.
Basically, It is impossible.
You don't measure the same thing.
your jpg file is first built in memory, and then wrote to disk. It is impossible the last operation which is extra makes the whole thing faster.
Advice: use a profiler to see where you spend time.
Make sure your code do the same thing for both memory and disk.