first version only dirs parralell
This commit is contained in:
6
.cargo/config.toml
Normal file
6
.cargo/config.toml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[build]
|
||||||
|
rustflags = [
|
||||||
|
"-C", "target-feature=+crt-static",
|
||||||
|
"-C", "link-arg=-static",
|
||||||
|
"-C", "link-arg=-no-pie"
|
||||||
|
]
|
||||||
9
.gitignore
vendored
Normal file
9
.gitignore
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
*
|
||||||
|
!.gitignore
|
||||||
|
!src
|
||||||
|
!src/**
|
||||||
|
!Cargo.toml
|
||||||
|
!tests
|
||||||
|
!tests/**
|
||||||
|
!.cargo
|
||||||
|
!.cargo/**
|
||||||
13
Cargo.toml
Normal file
13
Cargo.toml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
[package]
|
||||||
|
name='sexpkg'
|
||||||
|
version='0.1.0'
|
||||||
|
edition='2024'
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
rayon = "1.10.0"
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
opt-level = 3
|
||||||
|
lto = true
|
||||||
|
codegen-units = 1
|
||||||
|
panic = "abort"
|
||||||
38
src/main.rs
Normal file
38
src/main.rs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
use rayon::prelude::*;
|
||||||
|
use std::fs;
|
||||||
|
use std::io;
|
||||||
|
use std::path::Path;
|
||||||
|
use std::os::unix;
|
||||||
|
|
||||||
|
fn copy_recursive_hardlink_optimized(source: &Path, destination: &Path) -> io::Result<()> {
|
||||||
|
let metadata = fs::symlink_metadata(source)?;
|
||||||
|
|
||||||
|
if metadata.file_type().is_dir() {
|
||||||
|
fs::create_dir_all(destination)?;
|
||||||
|
|
||||||
|
let entries: Vec<_> = fs::read_dir(source)?.collect::<io::Result<Vec<_>>>()?;
|
||||||
|
entries.par_iter().try_for_each(|entry| {
|
||||||
|
let path = entry.path();
|
||||||
|
if let Some(file_name) = path.file_name() {
|
||||||
|
let dest_path = destination.join(file_name);
|
||||||
|
copy_recursive_hardlink_optimized(&path, &dest_path)
|
||||||
|
} else {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
})?;
|
||||||
|
} else if metadata.file_type().is_file() {
|
||||||
|
fs::hard_link(source, destination)?;
|
||||||
|
} else if metadata.file_type().is_symlink() {
|
||||||
|
let target = fs::read_link(source)?;
|
||||||
|
unix::fs::symlink(target, destination)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() -> io::Result<()> {
|
||||||
|
let source = Path::new("/usr/lib");
|
||||||
|
let destination = Path::new("/pkg/gnu/lib");
|
||||||
|
copy_recursive_hardlink_optimized(source, destination)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
35
tests/perfomanse.sh
Executable file
35
tests/perfomanse.sh
Executable file
@ -0,0 +1,35 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [ -z "$1" ]; then
|
||||||
|
echo "Usage: $0 <path_to_executable>"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
test_file="$1"
|
||||||
|
iterations=100
|
||||||
|
times=()
|
||||||
|
|
||||||
|
for i in $(seq 1 $iterations); do
|
||||||
|
rm -rf /pkg/gnu/lib
|
||||||
|
sleep 0.1
|
||||||
|
|
||||||
|
start_time=$(date +%s%N)
|
||||||
|
$test_file
|
||||||
|
end_time=$(date +%s%N)
|
||||||
|
|
||||||
|
elapsed_time=$((end_time - start_time))
|
||||||
|
elapsed_time_seconds=$(echo "scale=6; $elapsed_time / 1000000000" | bc)
|
||||||
|
times+=($elapsed_time_seconds)
|
||||||
|
done
|
||||||
|
|
||||||
|
sorted_times=($(printf '%s\n' "${times[@]}" | sort -n))
|
||||||
|
|
||||||
|
mid=$((iterations / 2))
|
||||||
|
if (( iterations % 2 == 1 )); then
|
||||||
|
median=${sorted_times[$mid]}
|
||||||
|
else
|
||||||
|
median=$(echo "scale=6; (${sorted_times[$mid]} + ${sorted_times[$((mid - 1))]} ) / 2" | bc)
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Test: $test_file"
|
||||||
|
echo "Median exec time: $median"
|
||||||
Reference in New Issue
Block a user