-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark_case.f90
89 lines (66 loc) · 2.07 KB
/
benchmark_case.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
module time_ascii
use iso_fortran_env, only: i64 => int64
implicit none
integer, parameter :: dp = kind(1.0d0)
abstract interface
subroutine inplace_transform(str)
character(len=*), intent(inout) :: str
end subroutine
end interface
contains
subroutine measure(transform,filename,sz)
procedure(inplace_transform) :: transform
character(len=*), intent(in) :: filename
integer, intent(in) :: sz
real(dp) :: time
character(len=:), allocatable :: chars
integer :: reps, unit, nreps
integer(i64) :: c1, c2, cr
call system_clock(count_rate=cr)
allocate(character(len=sz) :: chars)
open(newunit=unit,file=filename)
read(unit,'(a)') chars
chars(sz:sz) = ';'
close(unit)
nreps = 1
do
call system_clock(count=c1)
do reps = 1, nreps
call transform(chars)
end do
call system_clock(count=c2)
time = (real(c2 - c1,dp)/real(cr,dp))
if (time > 0.2_dp) exit
nreps = nreps * 2
end do
time = time / real(nreps,dp)
write(*,'(I16,2(2X,ES14.3),I16)') sz, sz / time, mb_per_s(sz,time), nreps
end subroutine
real(dp) function mb_per_s(sz,time)
integer, intent(in) :: sz
real(dp), intent(in) :: time
mb_per_s = ( real(sz,dp) / real(1024,dp)**2 ) / time
end function
end module
program benchmark_case
use ascii_simd, only: tolower, lower_sc
use time_ascii
implicit none
integer :: exp, sz
character(len=30) :: filename
write(*,'(4A16)') "size", "chars/s", "MB/s", "#reps"
print *, "--- tolower simd ---"
do exp = 3, 9
sz = 10**exp
write(filename,'(A,I0,A)') 'chars-',sz,'.txt'
! print *, filename
call measure(tolower,trim(filename), sz)
end do
! print *, "--- tolower select case ---"
! do exp = 3, 9
! sz = 10**exp
! write(filename,'(A,I0,A)') 'chars-',sz,'.txt'
! ! print *, filename
! call measure(lower_sc,trim(filename), sz)
! end do
end program