nordvpn icon indicating copy to clipboard operation
nordvpn copied to clipboard

Much faster "nordvpn list" patch

Open n8w8 opened this issue 6 years ago • 2 comments

Hi, thanks for the script. Here is an idea to make the "nordvpn list" function 100x faster.

# original with hot cache
time (
	find /etc/openvpn/client/ -type l -name "nordvpn_*${1}*.conf" \
	    | xargs -L1 basename \
	    | cut -d _ -f 2 \
	    | cut -d . -f 1 \
	    | sort -g
) > /tmp/nordvpn-list-orig

real	0m11,493s
user	0m0,388s
sys	0m2,560s

# equivalent but WAY faster
time (
	find /etc/openvpn/client/ -type l -name "nordvpn_*${1}*.conf" \
	    | rev \
	    | cut -f1 -d/ \
	    | rev \
	    | cut -d _ -f 2 \
	    | cut -d . -f 1 \
	    | sort -g
) > /tmp/nordvpn-list-new

real	0m0,071s
user	0m0,052s
sys	0m0,032s

# or, as the paths are hardcoded anyway, it can be faster still, but not noticeable:
time (
	find /etc/openvpn/client/ -type l -name "nordvpn_*${1}*.conf" \
	    | cut -d _ -f 2 \
	    | cut -d . -f 1 \
	    | sort -g
) > /tmp/nordvpn-list-new2

real	0m0,048s
user	0m0,032s
sys	0m0,008s

md5sum /tmp/nordvpn-list-*
a0b1355aaebbee7cad75152178a5fe19  /tmp/nordvpn-list-new
a0b1355aaebbee7cad75152178a5fe19  /tmp/nordvpn-list-new2
a0b1355aaebbee7cad75152178a5fe19  /tmp/nordvpn-list-orig

n8w8 avatar Dec 04 '18 07:12 n8w8

Sorry for not answering earlier. This is great! Could submit a pull request? Thanks!

nstinus avatar May 17 '19 11:05 nstinus

I almost never use Git(hub), and I lost my account login and notifications, without realizing it. So I couldn't give a pull request or reply earlier, sorry. But I see that in the meantime @drybalka has helped with merging it. Anyway, thanks both of you! edit: I don't know how to close the issue

n8w8 avatar Jul 25 '20 21:07 n8w8