Skip to content

Commit 2412bdb

Browse files
committed
Changed test_sorting.f90 to reduce run times
Changed sorted integer array from size 2**20 to size 2**16 Changed sorted character array from size 26**4 to 16**4, so the four characters are a-p. Changed sorted string array from size 26**3 to 16**3, so the four characters are a-p. Change format for the run times from F10.5 to F10.6 to give at least three digits of precision. [ticket: X]
1 parent 79ec20a commit 2412bdb

File tree

1 file changed

+31
-27
lines changed

1 file changed

+31
-27
lines changed

src/tests/sorting/test_sorting.f90

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ program test_sorting
44
compiler_version
55
use stdlib_kinds, only: int32, int64, dp, sp
66
use stdlib_sorting
7-
use stdlib_string_type, only: string_type, assignment(=), operator(>), operator(<), &
8-
write(formatted)
7+
use stdlib_string_type, only: string_type, assignment(=), operator(>), &
8+
operator(<), write(formatted)
99
use stdlib_error, only: check
1010

1111
implicit none
1212

13-
integer(int32), parameter :: test_size = 2_int32**20
14-
integer(int32), parameter :: char_size = 26**4
15-
integer(int32), parameter :: string_size = 26**3
13+
integer(int32), parameter :: test_size = 2_int32**16
14+
integer(int32), parameter :: char_size = 16**4
15+
integer(int32), parameter :: string_size = 16**3
1616
integer(int32), parameter :: block_size = test_size/6
17-
integer, parameter :: repeat = 8
17+
integer, parameter :: repeat = 1
1818

1919
integer(int32) :: &
2020
blocks(0:test_size-1), &
@@ -38,11 +38,12 @@ program test_sorting
3838
integer(int32) :: dummy(0:test_size-1)
3939
character(len=4) :: char_dummy(0:char_size-1)
4040
type(string_type) :: string_dummy(0:string_size-1)
41-
integer(int_size) :: index(0:test_size-1)
41+
integer(int_size) :: index(0:max(test_size, char_size, string_size)-1)
4242
integer(int32) :: work(0:test_size/2-1)
4343
character(len=4) :: char_work(0:char_size/2-1)
4444
type(string_type) :: string_work(0:string_size/2-1)
45-
integer(int_size) :: iwork(0:test_size/2-1)
45+
integer(int_size) :: iwork(0:max(test_size, char_size, &
46+
string_size)/2-1)
4647
integer :: count, i, index1, index2, j, k, l, temp
4748
real(sp) :: arand, brand
4849
character(*), parameter :: filename = 'test_sorting.txt'
@@ -91,10 +92,10 @@ program test_sorting
9192
end do
9293

9394
count = 0
94-
do i=0, 25
95-
do j=0, 25
96-
do k=0, 25
97-
do l=0, 25
95+
do i=0, 15
96+
do j=0, 15
97+
do k=0, 15
98+
do l=0, 15
9899
char_increase(count) = achar(97+i) // achar(97+j) // &
99100
achar(97+k) // achar(97+l)
100101
count = count + 1
@@ -117,9 +118,9 @@ program test_sorting
117118
end do
118119

119120
count = 0
120-
do i=0, 25
121-
do j=0, 25
122-
do k=0, 25
121+
do i=0, 15
122+
do j=0, 15
123+
do k=0, 15
123124
string_increase(count) = achar(97+i) // achar(97+j) // &
124125
achar(97+k)
125126
count = count + 1
@@ -171,7 +172,6 @@ program test_sorting
171172

172173
call test_string_sort_indexes( ldummy ); ltest = (ltest .and. ldummy)
173174

174-
175175
call check(ltest)
176176

177177
contains
@@ -244,7 +244,7 @@ subroutine test_int_ord_sort( a, a_name, ltest )
244244
write(*,'(a12, 2i7)') 'dummy(i-1:i) = ', dummy(i-1:i)
245245
end if
246246
write( lun, '("| Integer |", 1x, i7, 2x, "|", 1x, a15, " |", ' // &
247-
'a12, " |", F10.5, " |" )' ) &
247+
'a12, " |", F10.6, " |" )' ) &
248248
test_size, a_name, "Ord_Sort", tdiff/rate
249249

250250
!reverse
@@ -316,7 +316,7 @@ subroutine test_char_ord_sort( a, a_name, ltest )
316316
write(*,'(a, 2(1x,a4))') 'char_dummy(i-1:i) = ', char_dummy(i-1:i)
317317
end if
318318
write( lun, '("| Character |", 1x, i7, 2x, "|", 1x, a15, " |", ' // &
319-
'a12, " |", F10.5, " |" )' ) &
319+
'a12, " |", F10.6, " |" )' ) &
320320
char_size, a_name, "Ord_Sort", tdiff/rate
321321

322322
!reverse
@@ -393,7 +393,7 @@ subroutine test_string_ord_sort( a, a_name, ltest )
393393
string_dummy(i-1:i)
394394
end if
395395
write( lun, '("| String_type |", 1x, i7, 2x, "|", 1x, a15, " |", ' // &
396-
'a12, " |", F10.5, " |" )' ) &
396+
'a12, " |", F10.6, " |" )' ) &
397397
string_size, a_name, "Ord_Sort", tdiff/rate
398398

399399
!reverse
@@ -491,7 +491,7 @@ subroutine test_int_sort( a, a_name, ltest )
491491
write(*,'(a12, 2i7)') 'dummy(i-1:i) = ', dummy(i-1:i)
492492
end if
493493
write( lun, '("| Integer |", 1x, i7, 2x, "|", 1x, a15, " |", ' // &
494-
'a12, " |", F10.5, " |" )' ) &
494+
'a12, " |", F10.6, " |" )' ) &
495495
test_size, a_name, "Sort", tdiff/rate
496496

497497

@@ -556,7 +556,7 @@ subroutine test_char_sort( a, a_name, ltest )
556556
write(*,'(a17, 2(1x,a4))') 'char_dummy(i-1:i) = ', char_dummy(i-1:i)
557557
end if
558558
write( lun, '("| Character |", 1x, i7, 2x, "|", 1x, a15, " |", ' // &
559-
'a12, " |", F10.5, " |" )' ) &
559+
'a12, " |", F10.6, " |" )' ) &
560560
char_size, a_name, "Sort", tdiff/rate
561561

562562
!reverse
@@ -619,7 +619,7 @@ subroutine test_string_sort( a, a_name, ltest )
619619
string_dummy(i-1:i)
620620
end if
621621
write( lun, '("| String_type |", 1x, i7, 2x, "|", 1x, a15, " |", ' // &
622-
'a12, " |", F10.5, " |" )' ) &
622+
'a12, " |", F10.6, " |" )' ) &
623623
string_size, a_name, "Sort", tdiff/rate
624624

625625
! reverse
@@ -696,7 +696,7 @@ subroutine test_int_sort_index( a, a_name, ltest )
696696
end do
697697
tdiff = tdiff/repeat
698698

699-
dummy = a(index)
699+
dummy = a(index(0:size(a)-1))
700700
call verify_sort( dummy, valid, i )
701701
ltest = (ltest .and. valid)
702702
if ( .not. valid ) then
@@ -705,12 +705,12 @@ subroutine test_int_sort_index( a, a_name, ltest )
705705
write(*,'(a18, 2i7)') 'a(index(i-1:i)) = ', a(index(i-1:i))
706706
end if
707707
write( lun, '("| Integer |", 1x, i7, 2x, "|", 1x, a15, " |", ' // &
708-
'a12, " |", F10.5, " |" )' ) &
708+
'a12, " |", F10.6, " |" )' ) &
709709
test_size, a_name, "Sort_Index", tdiff/rate
710710

711711
dummy = a
712712
call sort_index( dummy, index, work, iwork, reverse=.true. )
713-
dummy = a(index)
713+
dummy = a(index(size(a)-1))
714714
call verify_reverse_sort( dummy, valid, i )
715715
ltest = (ltest .and. valid)
716716
if ( .not. valid ) then
@@ -754,21 +754,25 @@ subroutine test_char_sort_index( a, a_name, ltest )
754754
do i = 1, repeat
755755
char_dummy = a
756756
call system_clock( t0, rate )
757+
757758
call sort_index( char_dummy, index, char_work, iwork )
759+
758760
call system_clock( t1, rate )
761+
759762
tdiff = tdiff + t1 - t0
760763
end do
761764
tdiff = tdiff/repeat
762765

763766
call verify_char_sort( char_dummy, valid, i )
767+
764768
ltest = (ltest .and. valid)
765769
if ( .not. valid ) then
766770
write( *, * ) "SORT_INDEX did not sort " // a_name // "."
767771
write(*,*) 'i = ', i
768772
write(*,'(a17, 2(1x,a4))') 'char_dummy(i-1:i) = ', char_dummy(i-1:i)
769773
end if
770774
write( lun, '("| Character |", 1x, i7, 2x, "|", 1x, a15, " |", ' // &
771-
'a12, " |", F10.5, " |" )' ) &
775+
'a12, " |", F10.6, " |" )' ) &
772776
char_size, a_name, "Sort_Index", tdiff/rate
773777

774778
end subroutine test_char_sort_index
@@ -820,7 +824,7 @@ subroutine test_string_sort_index( a, a_name, ltest )
820824
string_dummy(i-1:i)
821825
end if
822826
write( lun, '("| String_type |", 1x, i7, 2x, "|", 1x, a15, " |", ' // &
823-
'a12, " |", F10.5, " |" )' ) &
827+
'a12, " |", F10.6, " |" )' ) &
824828
string_size, a_name, "Sort_Index", tdiff/rate
825829

826830
end subroutine test_string_sort_index

0 commit comments

Comments
 (0)