In an attempt to be clever, I used the complement function to remove the current page from the page collection, but that operation is very expensive compared to a conditional check.
$ hugo
Start building sites …
hugo v0.147.0-7d0039b86ddd6397816cc3383cb0cfa481b15f32+extended linux/amd64 BuildDate=2025-04-25T15:26:28Z VendorInfo=gohugoio
| EN
-------------------+--------
Pages | 36938
Paginator pages | 0
Non-page files | 5
Static files | 8
Processed images | 10
Aliases | 0
Cleaned | 0
Total in 51939 ms
Second run
$ hugo
Start building sites …
hugo v0.147.0-7d0039b86ddd6397816cc3383cb0cfa481b15f32+extended linux/amd64 BuildDate=2025-04-25T15:26:28Z VendorInfo=gohugoio
| EN
-------------------+--------
Pages | 36938
Paginator pages | 0
Non-page files | 5
Static files | 8
Processed images | 10
Aliases | 0
Cleaned | 0
Total in 51153 ms
So, it seems just about the same for me (I didn’t clear the public folder in all runs. Should I have?). Comp is low spec core-I5 3rd Gen with HDD and 8GB RAM, suitable for my writing blogs. Maybe the results are more visible on a higher spec setup?
Please do this again (the repo has changed) and post the console log:
git clone --single-branch -b hugo-forum-topic-54636 https://github.com/jmooring/hugo-testing hugo-forum-topic-54636
cd hugo-forum-topic-54636
hugo --logLevel info
INFO timer: name TestListRandomPagesMethodA count 10450 duration 4.655520497s average 445.504µs median 376.022µs
INFO timer: name TestListRandomPagesMethodB count 10450 duration 5.369023773s average 513.782µs median 416.176µs
INFO timer: name TestListRandomPagesMethodC count 10450 duration 16.532761861s average 1.582082ms median 1.049295ms
INFO timer: name TestGetPageCollection count 10450 duration 51.641570568s average 4.941777ms median 3.566887ms
INFO build: duration 27.481160439s
When you built the test site after I fixed the page collection creation:
INFO timer: name TestGetPageCollection count 10450 duration 211.465384ms average 20.235µs median 11.403µs
INFO timer: name TestListRandomPagesMethodA count 10450 duration 4.432601804s average 424.172µs median 369.769µs
INFO timer: name TestListRandomPagesMethodB count 10450 duration 5.96531728s average 570.843µs median 484.683µs
INFO timer: name TestListRandomPagesMethodC count 10450 duration 15.720986093s average 1.5044ms median 1.097591ms
INFO build: duration 14.040138775s
So we know two things:
The fix worked. The build time is now half of what it was.
Method A (using random numbers) is about 3x faster than Method C (shuffle).
And we also know that your PC is ridiculuously slow. The build time on my exceedingly average PC is 5s (1/3 of your build time).
You should have seen when it was on Windows! This site I shared built in 10 minutes and 5 minutes after excluding hugo.exe in the inbuilt antivirus. In Linux, the fact it builds below a minute has made amazed me. The comp is old by modern standards. So the build speed being slow is to be expected. I chose to stick with it instead of running Termux in my tablet.