You can test it using the time command. To answer your question, large operations might be run faster as root, as root has normally a more unrestricted access to system ressources than a usual user. Usually root is often able to use reserved disk space, which other users cannot use. So when doing large operations which might do benefit of this additional disk space (cause they might create a lot of temporary files) might speed up. Also a usual user might be limited by system environments like the /etc/security/limits.conf and similiar ones. Operations run by root are less likely to cause access denied failures, this might speed up or speed down the process, depending on the operation.
But for safety and security reasons you usually should not use root whenever possible.
# command find used as non root user
time find / >> /tmp/find_as_non_root.log
real 0m1,506s
user 0m0,202s
sys 0m0,521s
# command find used as root user
time find / >> /tmp/find_as_root.log
real 0m0,673s
user 0m0,194s
sys 0m0,470s
Is this answer evidence based or just conjecture? – Chris Davies
Oh look, what evidence...
My former test may be a bit inaccurate, as caching is indeed a factor involving. But my test shall show that processing time may be different when using a root user in contrast to using a non root user. So I give you another test, running the same commands 3 times in a row. By the way, you can try it for yourself.
# command find run 3 times in a row as non root user
time find / >> /tmp/find_as_non_root.log
real 0m0,618s
user 0m0,191s
sys 0m0,403s
time find / >> /tmp/find_as_non_root.log
real 0m0,648s
user 0m0,194s
sys 0m0,408s
time find / >> /tmp/find_as_non_root.log
real 0m0,704s
user 0m0,244s
sys 0m0,367s
# command find run 3 times in a row as root user
time find / >> /tmp/find_as_root.log
real 0m0.690s
user 0m0.270s
sys 0m0.412s
time find / >> /tmp/find_as_root.log
real 0m0.693s
user 0m0.210s
sys 0m0.474s
time find / >> /tmp/find_as_root.log
real 0m0.695s
user 0m0.182s
sys 0m0.504s
I've also added a 3th test:
# non root user
user@opensuse:~> time bash -c "for i in 1 2 3 4 5 6 7 8 9 10; do echo \$i; find / &> /dev/null; done;"
1
2
3
4
5
6
7
8
9
10
real 0m5,212s
user 0m1,833s
sys 0m3,314s
# root user
opensuse:~ # time bash -c "for i in 1 2 3 4 5 6 7 8 9 10; do echo \$i; find / &> /dev/null; done;"
1
2
3
4
5
6
7
8
9
10
real 0m6,214s
user 0m2,113s
sys 0m4,018s
I've made a fourth and last test.
This time I've created 2 partitions, formated with EXT2 file system, both are located on the same machine on the same harddrive and both are 100MiB in size.
I've mounted both filesystems and have used the following DANGEROUS script do fill the filesystem with random data, using the non root user.
DO NOT EXECUTE THE FOLLOWING SCRIPT, UNLESS YOU KNOW WHAT YOU ARE DOING!
#!/bin/sh
wheatgraindoubled=1
for iteration in $(seq 1 64)
do
echo "Iteration $iteration"
mkdir "$iteration"
cd "$iteration"
wheatgrain=0
while [ "$wheatgrain" -lt "$wheatgraindoubled" ]
do
wheatgrain=$(("$wheatgrain" + 1))
touch "$wheatgrain.dat"
dd if=/dev/urandom of="$wheatgrain.dat" count=8
done
wheatgraindoubled=$(("$wheatgraindoubled" * 2))
done
I waited for the script to fill the filesystem until no free space.
Then I used the same command to measure time, as in my previous test:
# non root user
user@opensuse:~> time bash -c "for i in 1 2 3 4 5 6 7 8 9 10; do echo \$i; find 1/ &> /dev/null; done;"
1
2
3
4
5
6
7
8
9
10
real 0m0,277s
user 0m0,101s
sys 0m0,176s
Then I copied all files using cp -r 1 /mnt/roottest/ as root user and repeated the same test.
# root user
opensuse:~ # time bash -c "for i in 1 2 3 4 5 6 7 8 9 10; do echo \$i; find 1/ &> /dev/null; done;"
1
2
3
4
5
6
7
8
9
10
real 0m0,263s
user 0m0,100s
sys 0m0,163s
Conclusion, root is processing faster than non root on a default opensuse installation.
time?