This code allocates memory (which is freed once the vectors is not referenced anywhere anymore. Could we be able to re-use memory in between all those calls of this function? That will be much faster then