Skip to content

Commit 1b93a60

Browse files
authored
Merge pull request #439 from wclodius2/sorting4
Sorting4
2 parents 1c6b2ae + 0386f3b commit 1b93a60

File tree

3 files changed

+155
-142
lines changed

3 files changed

+155
-142
lines changed

doc/specs/stdlib_sorting.md

+105-105
Original file line numberDiff line numberDiff line change
@@ -474,42 +474,42 @@ Sorting an array of a derived type based on the data in one component
474474
### Performance benchmarks
475475

476476
We have performed benchmarks of the procedures on nine different
477-
integer arrays each of size `2**20`:
477+
integer arrays each of size `2**16`:
478478

479479
* Blocks - the array is divided into six blocks, each of distinct
480480
uniformly increasing integers.
481-
* Decreasing - values decrease uniformly from `2**20-1` to `0`.
481+
* Decreasing - values decrease uniformly from `2**16-1` to `0`.
482482
* Identical - all integers have the same value of 10.
483-
* Increasing - values increase uniformly from `0` to `2**20-1`.
483+
* Increasing - values increase uniformly from `0` to `2**16-1`.
484484
* Random dense - the integers are generated randomly from a set of
485-
values from `0` to `2**18-1` so duplicates are dense.
486-
* Random order - a set of integers from `0` to `2**20 - 1` in random
485+
values from `0` to `2**14-1` so duplicates are dense.
486+
* Random order - a set of integers from `0` to `2**16 - 1` in random
487487
order.
488488
* Random sparse - the integers are generated randomly from a set of
489-
values from `0` to `2**22-1` so duplicates are sparse.
489+
values from `0` to `2**18-1` so duplicates are sparse.
490490
* Random-3 - the increasing array has 3 random exchanges of individual
491491
elements.
492492
* Random-10 - the final ten elements of the increasing array are
493493
replaced by random values.
494494

495495
On three different default character arrays, each of length 4 and of
496-
size `26**4`:
496+
size `20**4, with characters drawn from the set "a"-"p":
497497

498-
* Char. Decreasing - values decrease uniformly from `"zzzz"` to
498+
* Char. Decreasing - values decrease uniformly from `"pppp"` to
499499
`"aaaa"`.
500500
* Char. Increasing - values decrease uniformly from `"aaaa"` to
501-
`"zzzz"`.
502-
* Char. Random - the set of strings from `"aaaa"` to `"zzzz"` in
501+
`"pppp"`.
502+
* Char. Random - the set of strings from `"aaaa"` to `"pppp"` in
503503
random order.
504504

505505
On three different `string_type` arrays, each of length 4 elements and
506-
of size `26**3`:
506+
of size `16**3`, with characters drawn from the set "a"-"p":
507507

508-
* String Decreasing - values decrease uniformly from `"zzz"` to
508+
* String Decreasing - values decrease uniformly from `"ppp"` to
509509
`"aaa"`.
510510
* String Increasing - values decrease uniformly from `"aaa"` to
511-
`"zzz"`.
512-
* String Random - the set of strings from `"aaa"` to `"zzz"` in
511+
`"ppp"`.
512+
* String Random - the set of strings from `"aaa"` to `"ppp"` in
513513
random order.
514514

515515
These benchmarks have been performed on two different compilers, both
@@ -519,101 +519,101 @@ GB 2133 MHz LPDDR3 memory. The first compiler was GNU Fortran
519519

520520
| Type | Elements | Array Name | Method | Time (s) |
521521
|-------------|----------|-----------------|-------------|-----------|
522-
| Integer | 1048576 | Blocks | Ord_Sort | 0.00738 |
523-
| Integer | 1048576 | Decreasing | Ord_Sort | 0.00380 |
524-
| Integer | 1048576 | Identical | Ord_Sort | 0.00220 |
525-
| Integer | 1048576 | Increasing | Ord_Sort | 0.00209 |
526-
| Integer | 1048576 | Random dense | Ord_Sort | 0.17972 |
527-
| Integer | 1048576 | Random order | Ord_Sort | 0.17503 |
528-
| Integer | 1048576 | Random sparse | Ord_Sort | 0.17340 |
529-
| Integer | 1048576 | Random 3 | Ord_Sort | 0.00847 |
530-
| Integer | 1048576 | Random 10 | Ord_Sort | 0.00484 |
531-
| Character | 456976 | Char. Decrease | Ord_Sort | 0.00763 |
532-
| Character | 456976 | Char. Increase | Ord_Sort | 0.00414 |
533-
| Character | 456976 | Char. Random | Ord_Sort | 0.23746 |
534-
| String_type | 17576 | String Decrease | Ord_Sort | 0.00543 |
535-
| String_type | 17576 | String Increase | Ord_Sort | 0.00347 |
536-
| String_type | 17576 | String Random | Ord_Sort | 0.09461 |
537-
| Integer | 1048576 | Blocks | Sort | 0.10556 |
538-
| Integer | 1048576 | Decreasing | Sort | 0.13348 |
539-
| Integer | 1048576 | Identical | Sort | 0.15719 |
540-
| Integer | 1048576 | Increasing | Sort | 0.05316 |
541-
| Integer | 1048576 | Random dense | Sort | 0.15047 |
542-
| Integer | 1048576 | Random order | Sort | 0.15176 |
543-
| Integer | 1048576 | Random sparse | Sort | 0.15767 |
544-
| Integer | 1048576 | Random 3 | Sort | 0.19907 |
545-
| Integer | 1048576 | Random 10 | Sort | 0.34244 |
546-
| Character | 456976 | Char. Decrease | Sort | 0.30723 |
547-
| Character | 456976 | Char. Increase | Sort | 0.10984 |
548-
| Character | 456976 | Char. Random | Sort | 0.20642 |
549-
| String_type | 17576 | String Decrease | Sort | 0.15101 |
550-
| String_type | 17576 | String Increase | Sort | 0.05569 |
551-
| String_type | 17576 | String Random | Sort | 0.08499 |
552-
| Integer | 1048576 | Blocks | Sort_Index | 0.01163 |
553-
| Integer | 1048576 | Decreasing | Sort_Index | 0.00720 |
554-
| Integer | 1048576 | Identical | Sort_Index | 0.00451 |
555-
| Integer | 1048576 | Increasing | Sort_Index | 0.00452 |
556-
| Integer | 1048576 | Random dense | Sort_Index | 0.20295 |
557-
| Integer | 1048576 | Random order | Sort_Index | 0.20190 |
558-
| Integer | 1048576 | Random sparse | Sort_Index | 0.20221 |
559-
| Integer | 1048576 | Random 3 | Sort_Index | 0.01406 |
560-
| Integer | 1048576 | Random 10 | Sort_Index | 0.00765 |
561-
| Character | 456976 | Char. Decrease | Sort_Index | 0.00912 |
562-
| Character | 456976 | Char. Increase | Sort_Index | 0.00515 |
563-
| Character | 456976 | Char. Random | Sort_Index | 0.24693 |
564-
| String_type | 17576 | String Decrease | Sort_Index | 0.00528 |
565-
| String_type | 17576 | String Increase | Sort_Index | 0.00341 |
566-
| String_type | 17576 | String Random | Sort_Index | 0.09554 |
522+
| Integer | 65536 | Blocks | Ord_Sort | 0.000579 |
523+
| Integer | 65536 | Decreasing | Ord_Sort | 0.000212 |
524+
| Integer | 65536 | Identical | Ord_Sort | 0.000165 |
525+
| Integer | 65536 | Increasing | Ord_Sort | 0.000131 |
526+
| Integer | 65536 | Random dense | Ord_Sort | 0.009991 |
527+
| Integer | 65536 | Random order | Ord_Sort | 0.008574 |
528+
| Integer | 65536 | Random sparse | Ord_Sort | 0.010504 |
529+
| Integer | 65536 | Random 3 | Ord_Sort | 0.000532 |
530+
| Integer | 65536 | Random 10 | Ord_Sort | 0.000315 |
531+
| Character | 65536 | Char. Decrease | Ord_Sort | 0.001041 |
532+
| Character | 65536 | Char. Increase | Ord_Sort | 0.000584 |
533+
| Character | 65536 | Char. Random | Ord_Sort | 0.026273 |
534+
| String_type | 4096 | String Decrease | Ord_Sort | 0.001202 |
535+
| String_type | 4096 | String Increase | Ord_Sort | 0.000758 |
536+
| String_type | 4096 | String Random | Ord_Sort | 0.018180 |
537+
| Integer | 65536 | Blocks | Sort | 0.005073 |
538+
| Integer | 65536 | Decreasing | Sort | 0.005830 |
539+
| Integer | 65536 | Identical | Sort | 0.007372 |
540+
| Integer | 65536 | Increasing | Sort | 0.002421 |
541+
| Integer | 65536 | Random dense | Sort | 0.007006 |
542+
| Integer | 65536 | Random order | Sort | 0.007211 |
543+
| Integer | 65536 | Random sparse | Sort | 0.007109 |
544+
| Integer | 65536 | Random 3 | Sort | 0.012232 |
545+
| Integer | 65536 | Random 10 | Sort | 0.017345 |
546+
| Character | 65536 | Char. Decrease | Sort | 0.031350 |
547+
| Character | 65536 | Char. Increase | Sort | 0.011606 |
548+
| Character | 65536 | Char. Random | Sort | 0.022440 |
549+
| String_type | 4096 | String Decrease | Sort | 0.026539 |
550+
| String_type | 4096 | String Increase | Sort | 0.009755 |
551+
| String_type | 4096 | String Random | Sort | 0.016218 |
552+
| Integer | 65536 | Blocks | Sort_Index | 0.000953 |
553+
| Integer | 65536 | Decreasing | Sort_Index | 0.000418 |
554+
| Integer | 65536 | Identical | Sort_Index | 0.000264 |
555+
| Integer | 65536 | Increasing | Sort_Index | 0.000262 |
556+
| Integer | 65536 | Random dense | Sort_Index | 0.009563 |
557+
| Integer | 65536 | Random order | Sort_Index | 0.009592 |
558+
| Integer | 65536 | Random sparse | Sort_Index | 0.009691 |
559+
| Integer | 65536 | Random 3 | Sort_Index | 0.000781 |
560+
| Integer | 65536 | Random 10 | Sort_Index | 0.000455 |
561+
| Character | 65536 | Char. Decrease | Sort_Index | 0.001189 |
562+
| Character | 65536 | Char. Increase | Sort_Index | 0.000752 |
563+
| Character | 65536 | Char. Random | Sort_Index | 0.025767 |
564+
| String_type | 4096 | String Decrease | Sort_Index | 0.001411 |
565+
| String_type | 4096 | String Increase | Sort_Index | 0.000761 |
566+
| String_type | 4096 | String Random | Sort_Index | 0.018202 |
567567

568568
The second compiler was Intel(R) Fortran Intel(R) 64 Compiler Classic
569569
for applications running on Intel(R) 64, Version 2021.2.0 Build
570570
20210228_000000, with the following results:
571571

572-
| Type | Elements | Array Name | Method | Time (s) |
572+
| Type | Elements | Array Name | Method | Time (s) |
573573
|-------------|----------|-----------------|-------------|-----------|
574-
| Integer | 1048576 | Blocks | Ord_Sort | 0.00320 |
575-
| Integer | 1048576 | Decreasing | Ord_Sort | 0.00142 |
576-
| Integer | 1048576 | Identical | Ord_Sort | 0.00102 |
577-
| Integer | 1048576 | Increasing | Ord_Sort | 0.00158 |
578-
| Integer | 1048576 | Random dense | Ord_Sort | 0.09859 |
579-
| Integer | 1048576 | Random order | Ord_Sort | 0.09704 |
580-
| Integer | 1048576 | Random sparse | Ord_Sort | 0.09599 |
581-
| Integer | 1048576 | Random 3 | Ord_Sort | 0.00396 |
582-
| Integer | 1048576 | Random 10 | Ord_Sort | 0.00183 |
583-
| Character | 456976 | Char. Decrease | Ord_Sort | 0.00763 |
584-
| Character | 456976 | Char. Increase | Ord_Sort | 0.00341 |
585-
| Character | 456976 | Char. Random | Ord_Sort | 0.21991 |
586-
| String_type | 17576 | String Decrease | Ord_Sort | 0.01957 |
587-
| String_type | 17576 | String Increase | Ord_Sort | 0.00573 |
588-
| String_type | 17576 | String Random | Ord_Sort | 0.37850 |
589-
| Integer | 1048576 | Blocks | Sort | 0.03668 |
590-
| Integer | 1048576 | Decreasing | Sort | 0.04073 |
591-
| Integer | 1048576 | Identical | Sort | 0.03884 |
592-
| Integer | 1048576 | Increasing | Sort | 0.01279 |
593-
| Integer | 1048576 | Random dense | Sort | 0.06945 |
594-
| Integer | 1048576 | Random order | Sort | 0.07151 |
595-
| Integer | 1048576 | Random sparse | Sort | 0.07224 |
596-
| Integer | 1048576 | Random 3 | Sort | 0.07954 |
597-
| Integer | 1048576 | Random 10 | Sort | 0.14395 |
598-
| Character | 456976 | Char. Decrease | Sort | 0.30367 |
599-
| Character | 456976 | Char. Increase | Sort | 0.11316 |
600-
| Character | 456976 | Char. Random | Sort | 0.20233 |
601-
| String_type | 17576 | String Decrease | Sort | 0.64479 |
602-
| String_type | 17576 | String Increase | Sort | 0.23737 |
603-
| String_type | 17576 | String Random | Sort | 0.31361 |
604-
| Integer | 1048576 | Blocks | Sort_Index | 0.00643 |
605-
| Integer | 1048576 | Decreasing | Sort_Index | 0.00219 |
606-
| Integer | 1048576 | Identical | Sort_Index | 0.00126 |
607-
| Integer | 1048576 | Increasing | Sort_Index | 0.00130 |
608-
| Integer | 1048576 | Random dense | Sort_Index | 0.12911 |
609-
| Integer | 1048576 | Random order | Sort_Index | 0.13024 |
610-
| Integer | 1048576 | Random sparse | Sort_Index | 0.12956 |
611-
| Integer | 1048576 | Random 3 | Sort_Index | 0.00781 |
612-
| Integer | 1048576 | Random 10 | Sort_Index | 0.00281 |
613-
| Character | 456976 | Char. Decrease | Sort_Index | 0.00779 |
614-
| Character | 456976 | Char. Increase | Sort_Index | 0.00393 |
615-
| Character | 456976 | Char. Random | Sort_Index | 0.22561 |
616-
| String_type | 17576 | String Decrease | Sort_Index | 0.01878 |
617-
| String_type | 17576 | String Increase | Sort_Index | 0.00543 |
618-
| String_type | 17576 | String Random | Sort_Index | 0.37748 |
574+
| Integer | 65536 | Blocks | Ord_Sort | 0.000267 |
575+
| Integer | 65536 | Decreasing | Ord_Sort | 0.000068 |
576+
| Integer | 65536 | Identical | Ord_Sort | 0.000056 |
577+
| Integer | 65536 | Increasing | Ord_Sort | 0.000056 |
578+
| Integer | 65536 | Random dense | Ord_Sort | 0.004615 |
579+
| Integer | 65536 | Random order | Ord_Sort | 0.006325 |
580+
| Integer | 65536 | Random sparse | Ord_Sort | 0.004601 |
581+
| Integer | 65536 | Random 3 | Ord_Sort | 0.000193 |
582+
| Integer | 65536 | Random 10 | Ord_Sort | 0.000101 |
583+
| Character | 65536 | Char. Decrease | Ord_Sort | 0.001009 |
584+
| Character | 65536 | Char. Increase | Ord_Sort | 0.000529 |
585+
| Character | 65536 | Char. Random | Ord_Sort | 0.024547 |
586+
| String_type | 4096 | String Decrease | Ord_Sort | 0.003381 |
587+
| String_type | 4096 | String Increase | Ord_Sort | 0.000133 |
588+
| String_type | 4096 | String Random | Ord_Sort | 0.051985 |
589+
| Integer | 65536 | Blocks | Sort | 0.001614 |
590+
| Integer | 65536 | Decreasing | Sort | 0.001783 |
591+
| Integer | 65536 | Identical | Sort | 0.002111 |
592+
| Integer | 65536 | Increasing | Sort | 0.000674 |
593+
| Integer | 65536 | Random dense | Sort | 0.003574 |
594+
| Integer | 65536 | Random order | Sort | 0.003296 |
595+
| Integer | 65536 | Random sparse | Sort | 0.003380 |
596+
| Integer | 65536 | Random 3 | Sort | 0.003623 |
597+
| Integer | 65536 | Random 10 | Sort | 0.006839 |
598+
| Character | 65536 | Char. Decrease | Sort | 0.032564 |
599+
| Character | 65536 | Char. Increase | Sort | 0.012346 |
600+
| Character | 65536 | Char. Random | Sort | 0.022932 |
601+
| String_type | 4096 | String Decrease | Sort | 0.082140 |
602+
| String_type | 4096 | String Increase | Sort | 0.029591 |
603+
| String_type | 4096 | String Random | Sort | 0.043078 |
604+
| Integer | 65536 | Blocks | Sort_Index | 0.000848 |
605+
| Integer | 65536 | Decreasing | Sort_Index | 0.000103 |
606+
| Integer | 65536 | Identical | Sort_Index | 0.000102 |
607+
| Integer | 65536 | Increasing | Sort_Index | 0.000066 |
608+
| Integer | 65536 | Random dense | Sort_Index | 0.006434 |
609+
| Integer | 65536 | Random order | Sort_Index | 0.005941 |
610+
| Integer | 65536 | Random sparse | Sort_Index | 0.005957 |
611+
| Integer | 65536 | Random 3 | Sort_Index | 0.000326 |
612+
| Integer | 65536 | Random 10 | Sort_Index | 0.000175 |
613+
| Character | 65536 | Char. Decrease | Sort_Index | 0.001082 |
614+
| Character | 65536 | Char. Increase | Sort_Index | 0.000468 |
615+
| Character | 65536 | Char. Random | Sort_Index | 0.023100 |
616+
| String_type | 4096 | String Decrease | Sort_Index | 0.003292 |
617+
| String_type | 4096 | String Increase | Sort_Index | 0.000122 |
618+
| String_type | 4096 | String Random | Sort_Index | 0.049155 |
619619

src/stdlib_sorting.fypp

+5-4
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,9 @@ module stdlib_sorting
369369
module subroutine char_ord_sort( array, work, reverse )
370370
!! Version: experimental
371371
!!
372-
!! `char_ord_sort( array[, work, reverse] )` sorts the input `ARRAY` of type `CHARACTER(*)`
373-
!! using a hybrid sort based on the `'Rust" sort` algorithm found in `slice.rs`
372+
!! `char_ord_sort( array[, work, reverse] )` sorts the input `ARRAY` of type
373+
!! `CHARACTER(*)` using a hybrid sort based on the `'Rust" sort` algorithm
374+
!! found in `slice.rs`
374375
character(len=*), intent(inout) :: array(0:)
375376
character(len=len(array)), intent(out), optional :: work(0:)
376377
logical, intent(in), optional :: reverse
@@ -403,8 +404,8 @@ module stdlib_sorting
403404
pure module subroutine char_sort( array, reverse )
404405
!! Version: experimental
405406
!!
406-
!! `char_sort( array[, reverse] )` sorts the input `ARRAY` of type `CHARACTER(*)`
407-
!! using a hybrid sort based on the `introsort` of David Musser.
407+
!! `char_sort( array[, reverse] )` sorts the input `ARRAY` of type
408+
!! `CHARACTER(*)` using a hybrid sort based on the `introsort` of David Musser.
408409
!! The algorithm is of order O(N Ln(N)) for all inputs.
409410
!! Because it relies on `quicksort`, the coefficient of the O(N Ln(N))
410411
!! behavior is small for random data compared to other sorting algorithms.

0 commit comments

Comments
 (0)