From 18df6d26b3587ae61cf00a9e7fe4eae34f0fa5fc Mon Sep 17 00:00:00 2001 From: Jaewook Lee <11328376+jaewooklee93@users.noreply.github.com> Date: Fri, 9 Aug 2024 09:21:49 -0400 Subject: [PATCH 01/21] bash_aliases, vimrc: change dir --- bash_aliases.sh => linux-bash/bash_aliases.sh | 0 vimrc.vimrc => linux-bash/vimrc.vimrc | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename bash_aliases.sh => linux-bash/bash_aliases.sh (100%) rename vimrc.vimrc => linux-bash/vimrc.vimrc (100%) diff --git a/bash_aliases.sh b/linux-bash/bash_aliases.sh similarity index 100% rename from bash_aliases.sh rename to linux-bash/bash_aliases.sh diff --git a/vimrc.vimrc b/linux-bash/vimrc.vimrc similarity index 100% rename from vimrc.vimrc rename to linux-bash/vimrc.vimrc From f8ec1ba553f02cf1d2f43d2e95a96c523591729d Mon Sep 17 00:00:00 2001 From: Jaewook Lee <11328376+jaewooklee93@users.noreply.github.com> Date: Fri, 9 Aug 2024 09:23:19 -0400 Subject: [PATCH 02/21] main: add README.md --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8097107..d9bfb12 100644 --- a/README.md +++ b/README.md @@ -1 +1,9 @@ -# wiki \ No newline at end of file +# wiki + +```shell +mkdir -p ~/.config && cd ~/.config +git clone https://git.yauk.tv/jay817/wiki +ln -s $(pwd)/wiki/linux-bash/bash_aliases.sh ~/.bash_aliases +RC="$HOME/.${SHELL##*/}rc" && echo $RC +source "$RC" +``` From 144ffdf1c47f401638e0f3459bdfe9e0d614bd44 Mon Sep 17 00:00:00 2001 From: Jaewook Lee <11328376+jaewooklee93@users.noreply.github.com> Date: Fri, 9 Aug 2024 09:25:48 -0400 Subject: [PATCH 03/21] bashrc: add status --- linux-bash/bash_aliases.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/linux-bash/bash_aliases.sh b/linux-bash/bash_aliases.sh index a1bdf89..eed0aad 100644 --- a/linux-bash/bash_aliases.sh +++ b/linux-bash/bash_aliases.sh @@ -1,7 +1,7 @@ export RC="~/.bash_aliases" alias rc="vi $RC && tail $RC && source $HOME/.${SHELL##*/}rc" -alias l="ls -al --color=auto" +alias l="ls -l --color=auto" alias ls="ls -al --color=auto" alias ns="watch -n 0.1 nvidia-smi" alias log="docker compose logs -f" # compose V2 @@ -9,8 +9,6 @@ alias i="sudo apt-get install -y" alias debian="docker run -it --rm --gpus all python bash" alias download="huggingface-cli download" alias journal="sudo journalctl -u" -alias bsah="bash" # common typing error -alias pyhton="python" # common typing error alias make="make -j" export GGML_CUDA=1 @@ -25,6 +23,11 @@ alias dpkg="sudo dpkg" alias systemctl="sudo systemctl" alias service="sudo service" +alias bsah="bash" # common typing error +alias pyhton="python" # common typing error +alias stauts="status" +alias stuats="status" + dash() { sudo docker run -it --rm "$1" bash; } alias nuc="ssh 192.168.12.2" alias mac="ssh jaewooklee@192.168.12.45" From 243b7822b6f31faacc42f939c3df11d7ea356f81 Mon Sep 17 00:00:00 2001 From: Jaewook Lee <11328376+jaewooklee93@users.noreply.github.com> Date: Fri, 9 Aug 2024 22:26:53 +0900 Subject: [PATCH 04/21] bashrc: git remote to be verbose --- bash_aliases.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bash_aliases.sh b/bash_aliases.sh index a1bdf89..e6efe82 100644 --- a/bash_aliases.sh +++ b/bash_aliases.sh @@ -65,6 +65,7 @@ alias status="git status ." alias push="git push" alias pull="git pull" alias add="git add" +alias remote="git remote -v" commit() { git commit -m "$*" @@ -74,6 +75,9 @@ git() { if [[ "$1" == "diff" ]]; then shift command git diff --staged "$@" + elif [[ "$1" == "remote" ]]; then + shift + command git remote -v "$@" else command git "$@" fi From 1b8a4aeff29ad418c5a4740e1163aad9f4e380e3 Mon Sep 17 00:00:00 2001 From: Jaewook Lee <11328376+jaewooklee93@users.noreply.github.com> Date: Fri, 9 Aug 2024 22:35:36 +0900 Subject: [PATCH 05/21] bashrc: add git stash --- linux-bash/bash_aliases.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/linux-bash/bash_aliases.sh b/linux-bash/bash_aliases.sh index 8b03e11..4a5f360 100644 --- a/linux-bash/bash_aliases.sh +++ b/linux-bash/bash_aliases.sh @@ -69,6 +69,7 @@ alias push="git push" alias pull="git pull" alias add="git add" alias remote="git remote -v" +alias stash="git stash" commit() { git commit -m "$*" From 55903625585030f3fabaf0d508164232ed2fa72a Mon Sep 17 00:00:00 2001 From: Jaewook Lee <11328376+jaewooklee93@users.noreply.github.com> Date: Fri, 9 Aug 2024 22:45:52 +0900 Subject: [PATCH 06/21] vimrc: mouse drag ignore line no --- linux-bash/vimrc.vimrc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/linux-bash/vimrc.vimrc b/linux-bash/vimrc.vimrc index d9f439f..9ac2582 100644 --- a/linux-bash/vimrc.vimrc +++ b/linux-bash/vimrc.vimrc @@ -35,3 +35,5 @@ set background=dark " 어두운 배경 설정 " 파일 탐색기 설정 (NERDTree 사용 시) " 플러그인 설치 후 사용 " nmap :NERDTreeToggle " Ctrl+n으로 NERDTree 열기 + +se mouse+=a From 510f0a7d856cd1822a3324043bae630b5aeb4f51 Mon Sep 17 00:00:00 2001 From: Jaewook Lee <11328376+jaewooklee93@users.noreply.github.com> Date: Fri, 9 Aug 2024 23:10:12 +0900 Subject: [PATCH 07/21] bashrc: add git diff staged stat --- linux-bash/bash_aliases.sh | 9 +++++++-- linux-bash/vimrc.vimrc | 6 +++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/linux-bash/bash_aliases.sh b/linux-bash/bash_aliases.sh index 4a5f360..cf8c629 100644 --- a/linux-bash/bash_aliases.sh +++ b/linux-bash/bash_aliases.sh @@ -36,7 +36,9 @@ alias ping="ping -c 2" diff() { if [[ $# -eq 0 ]]; then - git diff --staged + clear + git status + git diff --staged else diff -qr "$@" fi @@ -70,7 +72,7 @@ alias pull="git pull" alias add="git add" alias remote="git remote -v" alias stash="git stash" - +alias vimrc="vi ~/.vimrc" commit() { git commit -m "$*" } @@ -82,6 +84,9 @@ git() { elif [[ "$1" == "remote" ]]; then shift command git remote -v "$@" + elif [[ "$1" == "status" ]]; then + command git status . + command git diff --staged --stat else command git "$@" fi diff --git a/linux-bash/vimrc.vimrc b/linux-bash/vimrc.vimrc index 9ac2582..146462b 100644 --- a/linux-bash/vimrc.vimrc +++ b/linux-bash/vimrc.vimrc @@ -18,7 +18,7 @@ set incsearch " 입력하는 동안 실시간 검색 set hlsearch " 검색 결과 하이라이트 " 기타 유용한 설정 -" set clipboard=unnamedplus " 시스템 클립보드 사용 +set clipboard=unnamedplus " 시스템 클립보드 사용 set autoindent " 자동 들여쓰기 set smartindent " 스마트 들여쓰기 set wrap " 줄 바꿈 @@ -35,5 +35,5 @@ set background=dark " 어두운 배경 설정 " 파일 탐색기 설정 (NERDTree 사용 시) " 플러그인 설치 후 사용 " nmap :NERDTreeToggle " Ctrl+n으로 NERDTree 열기 - -se mouse+=a +" +set mouse-=a From 9e5e4da5845681a04488db4d8fe1e57566dbc9df Mon Sep 17 00:00:00 2001 From: Jaewook Lee <11328376+jaewooklee93@users.noreply.github.com> Date: Fri, 9 Aug 2024 17:51:55 -0400 Subject: [PATCH 08/21] bsahrc: add my command --- linux-bash/bash_aliases.sh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/linux-bash/bash_aliases.sh b/linux-bash/bash_aliases.sh index cf8c629..634a09f 100644 --- a/linux-bash/bash_aliases.sh +++ b/linux-bash/bash_aliases.sh @@ -1,10 +1,19 @@ export RC="~/.bash_aliases" alias rc="vi $RC && tail $RC && source $HOME/.${SHELL##*/}rc" +alias my="sudo chown -R $(id -u):$(id -g)" + alias l="ls -l --color=auto" alias ls="ls -al --color=auto" alias ns="watch -n 0.1 nvidia-smi" -alias log="docker compose logs -f" # compose V2 +log() { + if [ $# -eq 0 ]; then + docker compose logs -f + else + docker logs -f "$@" + fi +} + alias i="sudo apt-get install -y" alias debian="docker run -it --rm --gpus all python bash" alias download="huggingface-cli download" From 29aa6902743b2ced3ede1b8311e551ce55e86ab3 Mon Sep 17 00:00:00 2001 From: Jaewook Lee <11328376+jaewooklee93@users.noreply.github.com> Date: Sat, 10 Aug 2024 06:52:55 +0900 Subject: [PATCH 09/21] bashrc: debian command change image --- linux-bash/bash_aliases.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux-bash/bash_aliases.sh b/linux-bash/bash_aliases.sh index 634a09f..89207da 100644 --- a/linux-bash/bash_aliases.sh +++ b/linux-bash/bash_aliases.sh @@ -15,7 +15,7 @@ log() { } alias i="sudo apt-get install -y" -alias debian="docker run -it --rm --gpus all python bash" +alias debian="docker run -it --rm --gpus all python:3.12 bash" alias download="huggingface-cli download" alias journal="sudo journalctl -u" alias make="make -j" From cbbde754a810388ed83cf6536baa67b1a7d970b9 Mon Sep 17 00:00:00 2001 From: Jaewook Lee <11328376+jaewooklee93@users.noreply.github.com> Date: Sun, 11 Aug 2024 14:01:10 +0900 Subject: [PATCH 10/21] bashrc: better git add --- linux-bash/bash_aliases.sh | 16 ++++++++++++++-- playwright/app.py | 15 +++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 playwright/app.py diff --git a/linux-bash/bash_aliases.sh b/linux-bash/bash_aliases.sh index 89207da..b5f7b4b 100644 --- a/linux-bash/bash_aliases.sh +++ b/linux-bash/bash_aliases.sh @@ -1,5 +1,6 @@ export RC="~/.bash_aliases" alias rc="vi $RC && tail $RC && source $HOME/.${SHELL##*/}rc" +alias bat="batcat --paging=never" alias my="sudo chown -R $(id -u):$(id -g)" @@ -47,6 +48,8 @@ diff() { if [[ $# -eq 0 ]]; then clear git status + echo + echo git diff --staged else diff -qr "$@" @@ -78,12 +81,19 @@ alias df="df -h" alias status="git status ." alias push="git push" alias pull="git pull" -alias add="git add" +add() { + if [ $# -eq 0 ]; then + git add . + else + git add $@ + fi + diff +} alias remote="git remote -v" alias stash="git stash" alias vimrc="vi ~/.vimrc" commit() { - git commit -m "$*" + git commit -m "$*" } git() { @@ -103,3 +113,5 @@ git() { alias cls="clear" alias weather="curl ko.wttr.in" + +alias dryblack="clear; black --check --diff --color ." diff --git a/playwright/app.py b/playwright/app.py new file mode 100644 index 0000000..812615b --- /dev/null +++ b/playwright/app.py @@ -0,0 +1,15 @@ +# pip install playwright && playwright install --with-deps + +import asyncio, threading, queue, io, pandas as pd +from playwright.async_api import async_playwright + +def GET(url, html = queue.Queue()): + async def aGET(P = async_playwright().start()): + html.put(await (await (await (await (await P) + .chromium.launch()).new_page()).goto(url)).text()) + threading.Thread(target=lambda: asyncio.run(aGET())).start() + return io.StringIO(html.get()) + +df = pd.read_html(GET('https://freeproxy.world/?type=socks5'))[0] +df = df.loc[df.Type == 'socks5'].reset_index(drop=True) +print(f'\x1b[92m{df}\x1b[0m') From 04d58ba1461fd628180e1afb8f50ac443b3959a4 Mon Sep 17 00:00:00 2001 From: Jaewook Lee <11328376+jaewooklee93@users.noreply.github.com> Date: Mon, 12 Aug 2024 16:51:22 +0900 Subject: [PATCH 11/21] debian-cpu-benchmark: initial commit --- .gitignore | 1 + debian-cpu-benchmark/bench.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 .gitignore create mode 100644 debian-cpu-benchmark/bench.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..763513e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.ipynb_checkpoints diff --git a/debian-cpu-benchmark/bench.py b/debian-cpu-benchmark/bench.py new file mode 100644 index 0000000..cad29dc --- /dev/null +++ b/debian-cpu-benchmark/bench.py @@ -0,0 +1,18 @@ +import subprocess, multiprocessing as mp, pandas as pd + +subprocess.run("sudo apt-get update && sudo apt-get install -y sysbench", + shell=True, stdout=subprocess.PIPE) + +def speed(core): + output = subprocess.getoutput( + f'sysbench cpu --threads={core} run | grep "events per second"') + output = float(output.split()[-1]) + print(output) + return output + +df = [] +for core in range(1, mp.cpu_count()+1): + s = speed(core) + df.append((core, s, s/core)) +df = pd.DataFrame(df) +df.to_csv('bench.csv', index=False) \ No newline at end of file From b1dd7f43a927c1c27f30b5b6f6b671b8ef6e3550 Mon Sep 17 00:00:00 2001 From: Jaewook Lee <11328376+jaewooklee93@users.noreply.github.com> Date: Mon, 12 Aug 2024 03:55:07 -0400 Subject: [PATCH 12/21] debian-cpu-benchmark: add gitignore --- debian-cpu-benchmark/.gitignore | 1 + debian-cpu-benchmark/bench.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 debian-cpu-benchmark/.gitignore mode change 100644 => 100755 debian-cpu-benchmark/bench.py diff --git a/debian-cpu-benchmark/.gitignore b/debian-cpu-benchmark/.gitignore new file mode 100644 index 0000000..df68529 --- /dev/null +++ b/debian-cpu-benchmark/.gitignore @@ -0,0 +1 @@ +bench.csv diff --git a/debian-cpu-benchmark/bench.py b/debian-cpu-benchmark/bench.py old mode 100644 new mode 100755 index cad29dc..ea9ac61 --- a/debian-cpu-benchmark/bench.py +++ b/debian-cpu-benchmark/bench.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python3 + import subprocess, multiprocessing as mp, pandas as pd subprocess.run("sudo apt-get update && sudo apt-get install -y sysbench", @@ -15,4 +17,4 @@ for core in range(1, mp.cpu_count()+1): s = speed(core) df.append((core, s, s/core)) df = pd.DataFrame(df) -df.to_csv('bench.csv', index=False) \ No newline at end of file +df.to_csv('bench.csv', index=False) From ba159467f2e6f97bd7ac1e76d0d9f59d4656891b Mon Sep 17 00:00:00 2001 From: Jaewook Lee <11328376+jaewooklee93@users.noreply.github.com> Date: Mon, 12 Aug 2024 17:05:58 +0900 Subject: [PATCH 13/21] debian-cpu-benchmark add sysbench install guide --- debian-cpu-benchmark/bench.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/debian-cpu-benchmark/bench.py b/debian-cpu-benchmark/bench.py index ea9ac61..a89e3c0 100755 --- a/debian-cpu-benchmark/bench.py +++ b/debian-cpu-benchmark/bench.py @@ -1,17 +1,20 @@ -#!/usr/bin/env python3 - import subprocess, multiprocessing as mp, pandas as pd -subprocess.run("sudo apt-get update && sudo apt-get install -y sysbench", - shell=True, stdout=subprocess.PIPE) - def speed(core): - output = subprocess.getoutput( - f'sysbench cpu --threads={core} run | grep "events per second"') - output = float(output.split()[-1]) - print(output) - return output - + try: + output = subprocess.run( + f'sysbench cpu --threads={core} run | grep "events per second"', + shell=True, capture_output=True, text=True).stdout.split()[-1] + print(output) + return output + except: + print('\n' + 'sudo apt-get update && sudo apt-get install -y sysbench' + '\tOR' + 'brew install sysbench' + '\n') + raise + df = [] for core in range(1, mp.cpu_count()+1): s = speed(core) From b4cd475846f8e667f40c04732bbed398e5e23dda Mon Sep 17 00:00:00 2001 From: Jaewook Lee <11328376+jaewooklee93@users.noreply.github.com> Date: Mon, 12 Aug 2024 17:09:49 +0900 Subject: [PATCH 14/21] cpu-benchmark: add shebang --- debian-cpu-benchmark/bench.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/debian-cpu-benchmark/bench.py b/debian-cpu-benchmark/bench.py index a89e3c0..6a56d4e 100755 --- a/debian-cpu-benchmark/bench.py +++ b/debian-cpu-benchmark/bench.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python + import subprocess, multiprocessing as mp, pandas as pd def speed(core): @@ -21,3 +23,4 @@ for core in range(1, mp.cpu_count()+1): df.append((core, s, s/core)) df = pd.DataFrame(df) df.to_csv('bench.csv', index=False) + From 62e1bf8edd6b7b39bd514ed63d69c25551809c87 Mon Sep 17 00:00:00 2001 From: Jaewook Lee <11328376+jaewooklee93@users.noreply.github.com> Date: Mon, 12 Aug 2024 17:45:24 +0900 Subject: [PATCH 15/21] cpu-benchmark: better interface --- debian-cpu-benchmark/bench.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/debian-cpu-benchmark/bench.py b/debian-cpu-benchmark/bench.py index 6a56d4e..dd85205 100755 --- a/debian-cpu-benchmark/bench.py +++ b/debian-cpu-benchmark/bench.py @@ -7,20 +7,26 @@ def speed(core): output = subprocess.run( f'sysbench cpu --threads={core} run | grep "events per second"', shell=True, capture_output=True, text=True).stdout.split()[-1] - print(output) - return output + return float(output) except: print('\n' - 'sudo apt-get update && sudo apt-get install -y sysbench' + 'sudo apt-get update && sudo apt-get install -y sysbench neofetch' '\tOR' - 'brew install sysbench' + 'brew install sysbench neofetch' '\n') raise +subprocess.run('neofetch') +R, G, B, W = (f'\x1b[{x}m' for x in (31, 32, 34, 0)) df = [] +print(f'\t{G}Speed\t\t{B} Speed') +print(f'\t{G}(multicore)\t{B}(per-core)') for core in range(1, mp.cpu_count()+1): + print(f'{R}Core: {core}', end='') s = speed(core) - df.append((core, s, s/core)) + row = (core, s, s/core) + print(f'\t{G}{int(row[1]):^8}\t{B}{int(row[2]):^8}') + df.append(row) +print(W) df = pd.DataFrame(df) df.to_csv('bench.csv', index=False) - From d8c159f5156df51855f961ace89d6a43e62909bf Mon Sep 17 00:00:00 2001 From: Jaewook Lee <11328376+jaewooklee93@users.noreply.github.com> Date: Mon, 12 Aug 2024 18:12:30 +0900 Subject: [PATCH 16/21] cpu-benchmark: add tabulate --- debian-cpu-benchmark/bench.py | 44 +++++++++++++++++------------------ 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/debian-cpu-benchmark/bench.py b/debian-cpu-benchmark/bench.py index dd85205..8332a8b 100755 --- a/debian-cpu-benchmark/bench.py +++ b/debian-cpu-benchmark/bench.py @@ -1,32 +1,30 @@ #!/usr/bin/env python -import subprocess, multiprocessing as mp, pandas as pd +import subprocess, multiprocessing as mp, warnings, pandas as pd +from tabulate import tabulate +warnings.filterwarnings("ignore") +R, G, B, W = (f'\x1b[{x}m' for x in (31, 32, 34, 0)) +subprocess.run('neofetch') def speed(core): - try: - output = subprocess.run( - f'sysbench cpu --threads={core} run | grep "events per second"', - shell=True, capture_output=True, text=True).stdout.split()[-1] - return float(output) - except: - print('\n' - 'sudo apt-get update && sudo apt-get install -y sysbench neofetch' - '\tOR' - 'brew install sysbench neofetch' - '\n') - raise - -subprocess.run('neofetch') -R, G, B, W = (f'\x1b[{x}m' for x in (31, 32, 34, 0)) + output = subprocess.run( + f'sysbench cpu --threads={core} run | grep "events per second"', + shell=True, capture_output=True, text=True).stdout.split()[-1] + return float(output) + df = [] -print(f'\t{G}Speed\t\t{B} Speed') -print(f'\t{G}(multicore)\t{B}(per-core)') -for core in range(1, mp.cpu_count()+1): - print(f'{R}Core: {core}', end='') +for core in range(1, mp.cpu_count()+2): s = speed(core) - row = (core, s, s/core) - print(f'\t{G}{int(row[1]):^8}\t{B}{int(row[2]):^8}') + row = { + '#Threads': core, + 'Throughput': s, + '(per-core)': s/core + } df.append(row) -print(W) df = pd.DataFrame(df) df.to_csv('bench.csv', index=False) + +df.iloc[:, 0] = df.iloc[:, 0].apply(lambda s: f'{R}{s}{W}') +df.iloc[:, 1] = df.iloc[:, 1].apply(lambda s: f'{G}{int(s)}{W}') +df.iloc[:, 2] = df.iloc[:, 2].apply(lambda s: f'{B}{int(s)}{W}') +print(tabulate(df, headers='keys', tablefmt='rounded_outline', showindex=False)) \ No newline at end of file From 710be724280ff2681ebe9d9e0df57eb1186cd7c8 Mon Sep 17 00:00:00 2001 From: Jaewook Lee <11328376+jaewooklee93@users.noreply.github.com> Date: Mon, 12 Aug 2024 18:18:45 +0900 Subject: [PATCH 17/21] cpu-bench: change dir --- cpu-bench/.gitignore | 1 + cpu-bench/bench.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 cpu-bench/.gitignore create mode 100755 cpu-bench/bench.py diff --git a/cpu-bench/.gitignore b/cpu-bench/.gitignore new file mode 100644 index 0000000..df68529 --- /dev/null +++ b/cpu-bench/.gitignore @@ -0,0 +1 @@ +bench.csv diff --git a/cpu-bench/bench.py b/cpu-bench/bench.py new file mode 100755 index 0000000..31968c2 --- /dev/null +++ b/cpu-bench/bench.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python + +import subprocess, multiprocessing as mp, warnings, pandas as pd +from tabulate import tabulate +warnings.filterwarnings("ignore") +R, G, B, W = (f'\x1b[{x}m' for x in (31, 32, 34, 0)) +subprocess.run('neofetch') + +def speed(core): + output = subprocess.run( + f'sysbench cpu --threads={core} run | grep "events per second"', + shell=True, capture_output=True, text=True).stdout.split()[-1] + return float(output) + +df = [] +for core in range(1, mp.cpu_count()+2): + s = speed(core) + row = { + '#Threads': core, + 'Throughput': s, + '(per-core)': s/core + } + df.append(row) +df = pd.DataFrame(df) +df.to_csv('bench.csv', index=False) + +df.iloc[:, 0] = df.iloc[:, 0].apply(lambda s: f'{R}{s}{W}') +df.iloc[:, 1] = df.iloc[:, 1].apply(lambda s: f'{G}{int(s)}{W}') +df.iloc[:, 2] = df.iloc[:, 2].apply(lambda s: f'{B}{int(s)}{W}') +print(tabulate(df, headers='keys', tablefmt='rounded_outline', showindex=False)) From ba882aed3b595139fc5d17fc828635b5e6e7a2b7 Mon Sep 17 00:00:00 2001 From: Jaewook Lee <11328376+jaewooklee93@users.noreply.github.com> Date: Mon, 12 Aug 2024 18:27:52 +0900 Subject: [PATCH 18/21] add command --- cpu-bench/bench.py | 3 ++- debian-cpu-benchmark/.gitignore | 1 - debian-cpu-benchmark/bench.py | 30 ------------------------------ 3 files changed, 2 insertions(+), 32 deletions(-) delete mode 100644 debian-cpu-benchmark/.gitignore delete mode 100755 debian-cpu-benchmark/bench.py diff --git a/cpu-bench/bench.py b/cpu-bench/bench.py index 31968c2..df9d097 100755 --- a/cpu-bench/bench.py +++ b/cpu-bench/bench.py @@ -5,6 +5,7 @@ from tabulate import tabulate warnings.filterwarnings("ignore") R, G, B, W = (f'\x1b[{x}m' for x in (31, 32, 34, 0)) subprocess.run('neofetch') +print(f'{R}$ sysbench cpu --threads={core} run | grep "events per second"{W}' def speed(core): output = subprocess.run( @@ -13,7 +14,7 @@ def speed(core): return float(output) df = [] -for core in range(1, mp.cpu_count()+2): +for core in range(1, mp.cpu_count()+1): s = speed(core) row = { '#Threads': core, diff --git a/debian-cpu-benchmark/.gitignore b/debian-cpu-benchmark/.gitignore deleted file mode 100644 index df68529..0000000 --- a/debian-cpu-benchmark/.gitignore +++ /dev/null @@ -1 +0,0 @@ -bench.csv diff --git a/debian-cpu-benchmark/bench.py b/debian-cpu-benchmark/bench.py deleted file mode 100755 index 8332a8b..0000000 --- a/debian-cpu-benchmark/bench.py +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env python - -import subprocess, multiprocessing as mp, warnings, pandas as pd -from tabulate import tabulate -warnings.filterwarnings("ignore") -R, G, B, W = (f'\x1b[{x}m' for x in (31, 32, 34, 0)) -subprocess.run('neofetch') - -def speed(core): - output = subprocess.run( - f'sysbench cpu --threads={core} run | grep "events per second"', - shell=True, capture_output=True, text=True).stdout.split()[-1] - return float(output) - -df = [] -for core in range(1, mp.cpu_count()+2): - s = speed(core) - row = { - '#Threads': core, - 'Throughput': s, - '(per-core)': s/core - } - df.append(row) -df = pd.DataFrame(df) -df.to_csv('bench.csv', index=False) - -df.iloc[:, 0] = df.iloc[:, 0].apply(lambda s: f'{R}{s}{W}') -df.iloc[:, 1] = df.iloc[:, 1].apply(lambda s: f'{G}{int(s)}{W}') -df.iloc[:, 2] = df.iloc[:, 2].apply(lambda s: f'{B}{int(s)}{W}') -print(tabulate(df, headers='keys', tablefmt='rounded_outline', showindex=False)) \ No newline at end of file From c6ee6626e5d49e4fa7253f6b74e8b170004ed27e Mon Sep 17 00:00:00 2001 From: Jaewook Lee <11328376+jaewooklee93@users.noreply.github.com> Date: Mon, 12 Aug 2024 18:31:14 +0900 Subject: [PATCH 19/21] cpu-bench: rename csv --- cpu-bench/.gitignore | 2 +- cpu-bench/bench.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cpu-bench/.gitignore b/cpu-bench/.gitignore index df68529..df2929e 100644 --- a/cpu-bench/.gitignore +++ b/cpu-bench/.gitignore @@ -1 +1 @@ -bench.csv +.csv diff --git a/cpu-bench/bench.py b/cpu-bench/bench.py index df9d097..14df329 100755 --- a/cpu-bench/bench.py +++ b/cpu-bench/bench.py @@ -5,7 +5,7 @@ from tabulate import tabulate warnings.filterwarnings("ignore") R, G, B, W = (f'\x1b[{x}m' for x in (31, 32, 34, 0)) subprocess.run('neofetch') -print(f'{R}$ sysbench cpu --threads={core} run | grep "events per second"{W}' +print(f'{G}$ sysbench cpu --threads=$(nproc) run | grep "events per second"{W}') def speed(core): output = subprocess.run( @@ -23,7 +23,7 @@ for core in range(1, mp.cpu_count()+1): } df.append(row) df = pd.DataFrame(df) -df.to_csv('bench.csv', index=False) +df.to_csv('result.csv', index=False) df.iloc[:, 0] = df.iloc[:, 0].apply(lambda s: f'{R}{s}{W}') df.iloc[:, 1] = df.iloc[:, 1].apply(lambda s: f'{G}{int(s)}{W}') From cc6dfa392f6cef3dcec09b1d734021f706464601 Mon Sep 17 00:00:00 2001 From: Jaewook Lee <11328376+jaewooklee93@users.noreply.github.com> Date: Mon, 12 Aug 2024 18:42:00 +0900 Subject: [PATCH 20/21] cpu-bench: change option --- cpu-bench/.gitignore | 2 +- cpu-bench/bench.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cpu-bench/.gitignore b/cpu-bench/.gitignore index df2929e..afed073 100644 --- a/cpu-bench/.gitignore +++ b/cpu-bench/.gitignore @@ -1 +1 @@ -.csv +*.csv diff --git a/cpu-bench/bench.py b/cpu-bench/bench.py index 14df329..3e24934 100755 --- a/cpu-bench/bench.py +++ b/cpu-bench/bench.py @@ -5,11 +5,11 @@ from tabulate import tabulate warnings.filterwarnings("ignore") R, G, B, W = (f'\x1b[{x}m' for x in (31, 32, 34, 0)) subprocess.run('neofetch') -print(f'{G}$ sysbench cpu --threads=$(nproc) run | grep "events per second"{W}') +print(f'{G}$ sysbench cpu --cpu-max-prime=20000 --time=1 --threads=$(nproc) run | grep second{W}') def speed(core): output = subprocess.run( - f'sysbench cpu --threads={core} run | grep "events per second"', + f'sysbench cpu --cpu-max-prime=20000 --time=1 --threads={core} run | grep second', shell=True, capture_output=True, text=True).stdout.split()[-1] return float(output) From bce640047754c05fc612cecbe1c69614fd0404af Mon Sep 17 00:00:00 2001 From: Jaewook Lee <11328376+jaewooklee93@users.noreply.github.com> Date: Mon, 12 Aug 2024 18:50:07 +0900 Subject: [PATCH 21/21] cpu-bench: add clear --- cpu-bench/bench.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/cpu-bench/bench.py b/cpu-bench/bench.py index 3e24934..d1d9613 100755 --- a/cpu-bench/bench.py +++ b/cpu-bench/bench.py @@ -1,16 +1,26 @@ #!/usr/bin/env python +def ensure(*packages): + for pkg in packages: + try: __import__(pkg) + except: import os; os.sytem(f'pip install -q {pkg}') +ensure('pandas', 'tabulate') + import subprocess, multiprocessing as mp, warnings, pandas as pd from tabulate import tabulate warnings.filterwarnings("ignore") R, G, B, W = (f'\x1b[{x}m' for x in (31, 32, 34, 0)) +subprocess.run('clear') subprocess.run('neofetch') -print(f'{G}$ sysbench cpu --cpu-max-prime=20000 --time=1 --threads=$(nproc) run | grep second{W}') + +command = lambda core: f'sysbench cpu --cpu-max-prime=20000 --time=1 --threads={core} run | grep second' + +print(f'{G}$ {command("$(nproc)")}{W}') def speed(core): output = subprocess.run( - f'sysbench cpu --cpu-max-prime=20000 --time=1 --threads={core} run | grep second', - shell=True, capture_output=True, text=True).stdout.split()[-1] + command(core), shell=True, capture_output=True, text=True + ).stdout.split()[-1] return float(output) df = [] @@ -18,7 +28,7 @@ for core in range(1, mp.cpu_count()+1): s = speed(core) row = { '#Threads': core, - 'Throughput': s, + 'Throughput(/s)': s, '(per-core)': s/core } df.append(row)