I have tested next sorting function:

- my one (just quick sort copy/past from the Internet)
- std::slice::sort_unstable
- pdqsort::sort

I sorted vector of &str with 1_00_000_000 items.

it takes on my PC

- 52 seconds
- 92 seconds
- 98 seconds

2 and 3 functions is about the same by mine wins almost in 2x times.

I use release mode and measure time with std::time::Instant::now()/now.elapsed().

Why library function for sorting too slow?

Does it make sense to use library functions to sort items if my function is so fast?

a bonus question I written one more program in golang where I am sorting items too and it takes 56 seconds like my custom quick sort function. It faster then sorting library written in rust.

golang uses pdqsort as my thrid function.

I measure time there with help

start := time.Now()

...

time.Since(start)

the code you can find below

```
fn main() {
let mut hash = std::collections::HashSet::new();
let now = std::time::Instant::now();
for i in 0..100_000_000 {
hash.insert(i.to_string());
}
println!("{:?} insert to hashmap", now.elapsed());
let now = std::time::Instant::now();
let mut v: Vec<&str> = hash.iter().map(|s| s.as_str()).collect();
println!("{:?} collect keys to vector", now.elapsed());
// let now = std::time::Instant::now();
// let i = quick_sort(&mut v);
// println!("{} {:?} custom sorting vector", i, now.elapsed());
// let now = std::time::Instant::now();
// pdqsort::sort(&mut v);
// println!("{:?} pdqsort sorting vector", now.elapsed());
let now = std::time::Instant::now();
v.sort_unstable();
println!("{:?} std sort sorting vector", now.elapsed());
}
pub fn quick_sort(arr: &mut [&str]) -> usize {
let len = arr.len();
_quick_sort(arr, 0, (len - 1) as isize)
}
fn _quick_sort(arr: &mut [&str], low: isize, high: isize) -> usize {
let mut i = 0;
if low < high {
let p = partition(arr, low, high);
_quick_sort(arr, low, p.0 - 1);
_quick_sort(arr, p.0 + 1, high);
i += p.1;
}
i
}
fn partition(arr: &mut [&str], low: isize, high: isize) -> (isize, usize) {
let pivot = high as usize;
let mut store_index = low - 1;
let mut last_index = high;
let mut i = 0;
loop {
i += 1;
store_index += 1;
while arr[store_index as usize] < arr[pivot] {
store_index += 1;
}
last_index -= 1;
while last_index >= 0 && arr[last_index as usize] > arr[pivot] {
last_index -= 1;
}
if store_index >= last_index {
break;
} else {
arr.swap(store_index as usize, last_index as usize);
}
}
arr.swap(store_index as usize, pivot);
(store_index, i)
}
```

```
package main
import (
"fmt"
"sort"
"strconv"
"time"
)
func main() {
basket := make(map[string]string)
start1 := time.Now()
for i := 0; i < 100000000; i++ {
basket[strconv.Itoa(i)] = strconv.Itoa(i)
}
fmt.Println(time.Since(start1), "insert to hashmap")
keys := make([]string, 0, len(basket))
start2 := time.Now()
for k := range basket {
keys = append(keys, k)
}
fmt.Println(time.Since(start2), "collect keys to vector")
start3 := time.Now()
sort.Strings(keys)
fmt.Println(time.Since(start3), "sorting vector")
}
```