44// file that was distributed with this source code.
55
66use divan:: { Bencher , black_box} ;
7+ use tempfile:: NamedTempFile ;
78use uu_sort:: uumain;
89use uucore:: benchmark:: { run_util_function, setup_test_file, text_data} ;
910
@@ -12,9 +13,14 @@ use uucore::benchmark::{run_util_function, setup_test_file, text_data};
1213fn sort_ascii_only ( bencher : Bencher , num_lines : usize ) {
1314 let data = text_data:: generate_ascii_data ( num_lines) ;
1415 let file_path = setup_test_file ( & data) ;
16+ let output_file = NamedTempFile :: new ( ) . unwrap ( ) ;
17+ let output_path = output_file. path ( ) . to_str ( ) . unwrap ( ) ;
1518
1619 bencher. bench ( || {
17- black_box ( run_util_function ( uumain, & [ file_path. to_str ( ) . unwrap ( ) ] ) ) ;
20+ black_box ( run_util_function (
21+ uumain,
22+ & [ "-o" , output_path, file_path. to_str ( ) . unwrap ( ) ] ,
23+ ) ) ;
1824 } ) ;
1925}
2026
@@ -23,9 +29,14 @@ fn sort_ascii_only(bencher: Bencher, num_lines: usize) {
2329fn sort_accented_data ( bencher : Bencher , num_lines : usize ) {
2430 let data = text_data:: generate_accented_data ( num_lines) ;
2531 let file_path = setup_test_file ( & data) ;
32+ let output_file = NamedTempFile :: new ( ) . unwrap ( ) ;
33+ let output_path = output_file. path ( ) . to_str ( ) . unwrap ( ) ;
2634
2735 bencher. bench ( || {
28- black_box ( run_util_function ( uumain, & [ file_path. to_str ( ) . unwrap ( ) ] ) ) ;
36+ black_box ( run_util_function (
37+ uumain,
38+ & [ "-o" , output_path, file_path. to_str ( ) . unwrap ( ) ] ,
39+ ) ) ;
2940 } ) ;
3041}
3142
@@ -34,9 +45,14 @@ fn sort_accented_data(bencher: Bencher, num_lines: usize) {
3445fn sort_mixed_data ( bencher : Bencher , num_lines : usize ) {
3546 let data = text_data:: generate_mixed_data ( num_lines) ;
3647 let file_path = setup_test_file ( & data) ;
48+ let output_file = NamedTempFile :: new ( ) . unwrap ( ) ;
49+ let output_path = output_file. path ( ) . to_str ( ) . unwrap ( ) ;
3750
3851 bencher. bench ( || {
39- black_box ( run_util_function ( uumain, & [ file_path. to_str ( ) . unwrap ( ) ] ) ) ;
52+ black_box ( run_util_function (
53+ uumain,
54+ & [ "-o" , output_path, file_path. to_str ( ) . unwrap ( ) ] ,
55+ ) ) ;
4056 } ) ;
4157}
4258
@@ -45,9 +61,14 @@ fn sort_mixed_data(bencher: Bencher, num_lines: usize) {
4561fn sort_case_sensitive ( bencher : Bencher , num_lines : usize ) {
4662 let data = text_data:: generate_case_sensitive_data ( num_lines) ;
4763 let file_path = setup_test_file ( & data) ;
64+ let output_file = NamedTempFile :: new ( ) . unwrap ( ) ;
65+ let output_path = output_file. path ( ) . to_str ( ) . unwrap ( ) ;
4866
4967 bencher. bench ( || {
50- black_box ( run_util_function ( uumain, & [ file_path. to_str ( ) . unwrap ( ) ] ) ) ;
68+ black_box ( run_util_function (
69+ uumain,
70+ & [ "-o" , output_path, file_path. to_str ( ) . unwrap ( ) ] ,
71+ ) ) ;
5172 } ) ;
5273}
5374
@@ -56,11 +77,13 @@ fn sort_case_sensitive(bencher: Bencher, num_lines: usize) {
5677fn sort_case_insensitive ( bencher : Bencher , num_lines : usize ) {
5778 let data = text_data:: generate_case_sensitive_data ( num_lines) ;
5879 let file_path = setup_test_file ( & data) ;
80+ let output_file = NamedTempFile :: new ( ) . unwrap ( ) ;
81+ let output_path = output_file. path ( ) . to_str ( ) . unwrap ( ) ;
5982
6083 bencher. bench ( || {
6184 black_box ( run_util_function (
6285 uumain,
63- & [ "-f" , file_path. to_str ( ) . unwrap ( ) ] ,
86+ & [ "-f" , "-o" , output_path , file_path. to_str ( ) . unwrap ( ) ] ,
6487 ) ) ;
6588 } ) ;
6689}
@@ -70,11 +93,13 @@ fn sort_case_insensitive(bencher: Bencher, num_lines: usize) {
7093fn sort_dictionary_order ( bencher : Bencher , num_lines : usize ) {
7194 let data = text_data:: generate_mixed_data ( num_lines) ;
7295 let file_path = setup_test_file ( & data) ;
96+ let output_file = NamedTempFile :: new ( ) . unwrap ( ) ;
97+ let output_path = output_file. path ( ) . to_str ( ) . unwrap ( ) ;
7398
7499 bencher. bench ( || {
75100 black_box ( run_util_function (
76101 uumain,
77- & [ "-d" , file_path. to_str ( ) . unwrap ( ) ] ,
102+ & [ "-d" , "-o" , output_path , file_path. to_str ( ) . unwrap ( ) ] ,
78103 ) ) ;
79104 } ) ;
80105}
@@ -92,10 +117,13 @@ fn sort_numeric(bencher: Bencher, num_lines: usize) {
92117
93118 let file_path = setup_test_file ( & data) ;
94119
120+ let output_file = NamedTempFile :: new ( ) . unwrap ( ) ;
121+ let output_path = output_file. path ( ) . to_str ( ) . unwrap ( ) ;
122+
95123 bencher. bench ( || {
96124 black_box ( run_util_function (
97125 uumain,
98- & [ "-n" , file_path. to_str ( ) . unwrap ( ) ] ,
126+ & [ "-n" , "-o" , output_path , file_path. to_str ( ) . unwrap ( ) ] ,
99127 ) ) ;
100128 } ) ;
101129}
@@ -105,11 +133,13 @@ fn sort_numeric(bencher: Bencher, num_lines: usize) {
105133fn sort_reverse_locale ( bencher : Bencher , num_lines : usize ) {
106134 let data = text_data:: generate_accented_data ( num_lines) ;
107135 let file_path = setup_test_file ( & data) ;
136+ let output_file = NamedTempFile :: new ( ) . unwrap ( ) ;
137+ let output_path = output_file. path ( ) . to_str ( ) . unwrap ( ) ;
108138
109139 bencher. bench ( || {
110140 black_box ( run_util_function (
111141 uumain,
112- & [ "-r" , file_path. to_str ( ) . unwrap ( ) ] ,
142+ & [ "-r" , "-o" , output_path , file_path. to_str ( ) . unwrap ( ) ] ,
113143 ) ) ;
114144 } ) ;
115145}
@@ -130,11 +160,14 @@ fn sort_key_field(bencher: Bencher, num_lines: usize) {
130160
131161 let file_path = setup_test_file ( & data) ;
132162
163+ let output_file = NamedTempFile :: new ( ) . unwrap ( ) ;
164+ let output_path = output_file. path ( ) . to_str ( ) . unwrap ( ) ;
165+
133166 bencher. bench ( || {
134167 // Sort by second field
135168 black_box ( run_util_function (
136169 uumain,
137- & [ "-k" , "2" , file_path. to_str ( ) . unwrap ( ) ] ,
170+ & [ "-k" , "2" , "-o" , output_path , file_path. to_str ( ) . unwrap ( ) ] ,
138171 ) ) ;
139172 } ) ;
140173}
@@ -144,11 +177,13 @@ fn sort_key_field(bencher: Bencher, num_lines: usize) {
144177fn sort_unique_locale ( bencher : Bencher , num_lines : usize ) {
145178 let data = text_data:: generate_accented_data ( num_lines) ;
146179 let file_path = setup_test_file ( & data) ;
180+ let output_file = NamedTempFile :: new ( ) . unwrap ( ) ;
181+ let output_path = output_file. path ( ) . to_str ( ) . unwrap ( ) ;
147182
148183 bencher. bench ( || {
149184 black_box ( run_util_function (
150185 uumain,
151- & [ "-u" , file_path. to_str ( ) . unwrap ( ) ] ,
186+ & [ "-u" , "-o" , output_path , file_path. to_str ( ) . unwrap ( ) ] ,
152187 ) ) ;
153188 } ) ;
154189}
0 commit comments