A practical comparison using insertion sort, as you can see C is much faster. Note that these are attempts at a 1-to-1, in the real world you would just use Python's sort which uses https://en.wikipedia.org/wiki/Timsort and is far more efficient. Results:
Python
real 0m0.034s
user 0m0.028s
sys 0m0.008s
C
real 0m0.003s
user 0m0.000s
sys 0m0.000s
First in Python
#!/usr/bin/python
a = [16, 7, 4, 10, 18, 15, 6, 12, 13, 5, 11, 14, 17, 8, 2, 9, 19, 3, 1]
print 'Unsorted: %s' % a
def insertion_sort(a):
for j in range(1, len(a)):
key = a[j]
i = j - 1
while i >= 0 and a[i] > key:
a[i+1] = a[i]
i = i - 1
a[i+1] = key
return a
# execute the sort
print 'Sorted: %s' % insertion_sort(a)
second in C
#include <stdio.h>
#include <stdlib.h>
/*
Compile with:
cc insertion-sort.c -o insertion-sort
*/
int main(int argc, char **argv)
{
int a[20] = {16, 7, 4, 10, 18, 15, 6, 12, 13, 5, 11, 14, 17, 8, 2, 9, 20, 19, 3, 1};
int i, j, key;
int len = 20;
printf("Unsorted: [");
for ( i = 0; i < len; i++ ) {
printf(" %d ", a[i]);
}
printf("]\n");
for ( j = 0 ; j < len ; j++ )
{
key = a[j];
i = j - 1;
while ( i >= 0 && a[i] > key ) {
a[i + 1] = a[i];
i = i - 1;
}
a[i + 1] = key;
}
printf("Sorted: [");
for ( i = 0; i < len; i++ ) {
printf(" %d ", a[i]);
}
printf("]\n");
}