If I run the first program with gfortran on an Intel(R) Core™ i7-5500U CPU @ 2.40GHz (the time in seconds is on the right):
- Original program (without module, without
intent(in)):
$ gfortran vsrch.f90
$ time ./a.out 10000
Found 10001 100000 5 11.4076843
- With just a module:
$ time ./a.out 10000
Found 10001 100000 5 11.6750689
- With the module and the three
intent(in):
$ time ./a.out 10000
Found 10001 100000 5 4.64428234
- With the module and the three
intent(in)and-O3:
$ time ./a.out 10000
Found 10001 100000 5 2.95242286
It seems even a little better (~2.85-2.90) with -Os (size optimization).