Skip to content

Instantly share code, notes, and snippets.

@TIBTHINK
Last active July 31, 2025 00:41
Show Gist options
  • Select an option

  • Save TIBTHINK/cfba90cee4a34fca3a754f161b8996b7 to your computer and use it in GitHub Desktop.

Select an option

Save TIBTHINK/cfba90cee4a34fca3a754f161b8996b7 to your computer and use it in GitHub Desktop.
linux kernal benchmark
#!/bin/bash
set -e
# === SETTINGS ===
REPO_URL="https://github.com/torvalds/linux.git"
WORKDIR="$HOME/kernel-benchmark-github"
SRC_DIR="$WORKDIR/linux"
CORES=$(nproc)
# === FUNCTIONS ===
install_dependencies() {
echo "πŸ”§ Installing build dependencies..."
sudo apt update
sudo apt install -y build-essential libncurses-dev bison flex libssl-dev libelf-dev bc git curl wget
}
clone_or_update_repo() {
mkdir -p "$WORKDIR"
cd "$WORKDIR"
if [ -d "$SRC_DIR/.git" ]; then
echo "πŸ“¦ Updating existing Linux kernel repo..."
cd "$SRC_DIR"
git pull --depth=1 origin master
else
echo "πŸ“₯ Cloning Linux kernel from GitHub..."
git clone --depth=1 "$REPO_URL"
cd "$SRC_DIR"
fi
}
build_kernel() {
echo "βš™οΈ Preparing kernel config..."
if [ -f /boot/config-$(uname -r) ]; then
cp /boot/config-$(uname -r) .config
yes "" | make olddefconfig
else
make defconfig
fi
echo "πŸš€ Starting kernel compilation using $CORES cores..."
START=$(date +%s)
make -j"$CORES"
END=$(date +%s)
DURATION=$((END - START))
echo "βœ… Kernel compiled in $DURATION seconds."
}
# === MAIN ===
echo "🧠 Detected $CORES CPU cores."
install_dependencies
clone_or_update_repo
build_kernel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment