Skip to main content

SG against C on Windows

The programs of SG against C, measured again on Windows. How the numbers are taken is in How it is measured.

How it was run​

Measured on Windows (python3 bench/run.py, the hundred-and-second slice): Windows 11 on 64-bit Arm in a virtual machine on the Mac of SG against C, Clang 23 with C's library in the program (/MT, as sg build links), best of five after a run that is not timed, which also leaves out the first start of a new program (which on Windows took seconds now and then; why was not looked into); spawn, spawnasync, capture, pipelines and pipesasync are one timed run each (--runs 1), since five thousand starts take over twenty seconds there. The last column is the same ratio on macOS, from SG against C or from the program's choice. Windows on x86-64 is not measured: there is no such machine here, and the machines of the CI are shared and give no steady numbers.

The table​

ProgramSG, releaseSG, overflow checkedCrelease / Con macOS
fib0.276 s0.393 s0.273 s1.010.98
primes0.488 s0.475 s0.471 s1.040.99
collatz0.339 s0.540 s0.340 s1.001.00
words1.155 s1.094 s1.100 s1.051.02
list0.433 s0.444 s0.431 s1.001.01
expr0.342 s0.346 s0.338 s1.011.02
parse0.286 s0.315 s0.284 s1.010.99
vector2.117 s2.371 s2.114 s1.001.02
counts0.408 s0.404 s0.343 s1.191.20
show2.876 s3.025 s8.363 s0.340.47
lookup0.501 s0.488 s0.483 s1.041.01
buffer0.287 s0.300 s0.287 s1.000.99
bits0.339 s0.303 s0.369 s0.920.79
hash0.132 s0.134 s0.131 s1.011.00
nbody0.669 s0.669 s0.673 s0.990.97
numbers0.222 s0.225 s0.498 s0.450.95
floats0.182 s0.195 s0.735 s0.250.23
fields1.349 s1.358 s1.487 s0.911.02
lines0.072 s0.098 s0.454 s0.160.82
copy0.160 s0.187 s0.910 s0.180.54
bytes0.061 s0.059 s0.064 s0.950.94
table2.524 s2.476 s3.325 s0.760.52
blocks0.107 s0.120 s0.117 s0.911.00
keywords0.233 s0.234 s0.216 s1.081.03
classes0.209 s0.269 s0.234 s0.890.87
rewrite0.575 s0.625 s0.720 s0.800.94
tree0.194 s0.244 s0.114 s1.711.53
tasks0.121 s0.189 s0.123 s0.991.00
async0.236 s0.354 s0.208 s1.141.08
asynclines0.153 s0.171 s0.458 s0.331.28
tasklist0.534 s0.746 s0.445 s1.201.24
asynccopy0.384 s0.434 s0.920 s0.421.04
echo0.861 s0.850 s0.769 s1.120.89
echosync0.873 s0.778 s0.769 s1.130.99
echowork0.456 s0.457 s0.551 s0.831.02
netlines0.096 s0.132 s0.111 s0.861.14
ring0.343 s0.342 s0.343 s1.001.00
crc2.800 s2.798 s2.798 s1.000.99
deflate1.312 s1.311 s1.279 s1.031.04
clock0.237 s0.228 s0.236 s1.011.01
dates0.123 s0.303 s0.106 s1.160.29
rng0.115 s0.115 s0.115 s1.001.00
secure0.137 s0.137 s0.139 s0.981.00
listing0.316 s0.316 s0.276 s1.140.99
status11.688 s11.795 s15.677 s0.751.00
spawn22.829 s22.798 s22.761 s1.000.70
capture1.096 s1.279 s1.337 s0.821.49
pipelines0.091 s0.113 s0.502 s0.180.85
pipesasync0.153 s0.166 s0.507 s0.301.03
spawnasync22.644 s23.007 s22.968 s0.990.71
case0.176 s0.179 s5.273 s0.030.23
letters0.295 s0.376 s4.692 s0.060.10
udpecho1.089 s1.080 s1.365 s0.801.19
udpechosync1.299 s1.306 s1.284 s1.011.00
inline1.015 s1.012 s1.012 s1.001.03
callback0.914 s0.925 s0.913 s1.001.00
sqlite0.300 s0.301 s0.301 s1.001.00
curl0.366 s0.367 s0.365 s1.001.02
signals0.008 s0.007 s0.246 s0.031.27
bitfields0.371 s0.335 s0.352 s1.050.91
atomics0.226 s0.212 s0.260 s0.871.02
queue0.247 s0.250 s0.255 s0.971.39
library0.582 s0.576 s0.568 s1.021.01
kernel (size)5168 B2236 B2.312.31

How the C differs on Windows​

The C is the same program wherever it can be. Where POSIX has a function Windows has not, the C takes Windows' own (bench/windows/posix.h): threads of _beginthreadex and locks of SRWLOCK, as SG's runtime has them there; Winsock; getline written over fgets, and the input read as bytes; popen through cmd.exe. clock reads QueryPerformanceCounter, secure calls BCryptGenRandom, listing lists with FindFirstFileExW, spawn and capture start CreateProcessW, netlines cuts its lines out of what recv gives (Windows' C library cannot open a FILE over a socket), and signals is C's signal and raise with SIGTERM and a pipe of C's library, since Windows has no SIGUSR1. dates takes the moments apart by hand (Howard Hinnant's civil_from_days), since gmtime_s refuses a moment before 1970: so on Windows it is the same algorithm in both, where on macOS it is the C library's gmtime_r. Windows has no cat and no true, so run.py builds both from bench/windows and puts them first on PATH, for SG and C alike. case is compared by the size of its text only: its C maps a character to one by the tables of the C library, and Windows' writes three bytes more each line.

What the numbers say​

Most of the rest is the time of C, as on macOS. Where SG is much faster, the difference is Windows' C library: printf (show, numbers, floats), fgets (lines, copy, asynccopy, pipelines, pipesasync) and the functions of wide characters (case, letters) are several times slower there than on macOS, and SG uses none of them. signals is 0.03 because Signals.raise on Windows hands the signal on inside the program, where C's raise calls the handler, which writes into a pipe. Where SG is slower: tree, counts, async and tasklist as on macOS; dates, listing, echo and echosync on Windows only, in Slower than C.