Skip to content

Instantly share code, notes, and snippets.

@Grocel
Last active January 23, 2024 19:58
Show Gist options
  • Save Grocel/7ab3bc42a129a37be62681d2db8afbbb to your computer and use it in GitHub Desktop.
Save Grocel/7ab3bc42a129a37be62681d2db8afbbb to your computer and use it in GitHub Desktop.
GMod file.Exists loadtime test setup (1 addon with 50k sounds)

Setup

This is the testing setup I used to write up the report: Facepunch/garrysmod-issues#5674

Other setups

Benchmark

Test case: Addon With many sounds

Addon generator (create_dummy_addon_many_sounds50k.bat)

This works similar as the test case for 500 addons, execpt it creates a single addon called _test_addon_many_sounds.

Test addon content

The scripts will insert 50k copies of a very short but valid sound file to _test_addon_many_sounds\sound\_test_addon_many_sounds. The sound content is defined in dummySoundFileData.

The sound files represent any non lua content such as models, textures or maps.

Performance

This test case does NOT have any significant influence to the reported issue.

@echo off
rem Put in "addons" folder
set basedir=%~dp0
setlocal ENABLEDELAYEDEXPANSION
cd %basedir%
rem How many sound files do you need?
set /A soundCountFolderLevel1=100
set /A soundCountFolderLevel2=10
set /A soundCountPerFolder=50
set /A soundCountDisplay=%soundCountFolderLevel1%*%soundCountFolderLevel2%*%soundCountPerFolder%
set addonFolderName=_test_addon_many_sounds
set testSoundFolder=%addonFolderName%\sound\_test_addon_many_sounds
echo This will create %soundCountDisplay% sound files into the test addon "%addonFolderName%".
set /P continueScript=Do you want to continue (Y/[N])?
IF /I "%continueScript%" NEQ "Y" GOTO FINISH
rem Temporary file name for the sound file
set dummySoundFile=_dummy_sound.wav
rem A copy of sound/synth/sine_1760.wav from Wiremod as hex code
set dummySoundFileData= ^
52 49 46 46 B6 00 00 00 57 41 56 45 66 6D 74 20 ^
10 00 00 00 01 00 01 00 44 AC 00 00 88 58 01 00 ^
02 00 10 00 64 61 74 61 32 00 00 00 8E F5 10 E0 ^
91 CC 49 BC 3F B0 31 A9 92 A7 79 AB AC B4 94 C2 ^
54 D4 CF E8 BD FE BF 14 76 29 94 3B F9 49 BD 53 ^
44 58 46 57 D2 50 50 45 78 35 48 22 F2 0C 63 75 ^
65 20 1C 00 00 00 01 00 00 00 01 00 00 00 00 00 ^
00 00 64 61 74 61 00 00 00 00 00 00 00 00 00 00 ^
00 00 4C 49 53 54 34 00 00 00 61 64 74 6C 6C 74 ^
78 74 14 00 00 00 01 00 00 00 19 00 00 00 72 67 ^
6E 20 00 00 00 00 00 00 00 00 6C 61 62 6C 0C 00 ^
00 00 01 00 00 00 4C 6F 6F 70 20 30 31 00
echo.
echo Deleting %addonFolderName%
rd /S /Q %addonFolderName% 2> nul
echo Deleted %addonFolderName%
mkdir %addonFolderName% 2> nul
mkdir %testSoundFolder% 2> nul
echo.
echo Creating dummy sound file: %dummySoundFile%
del /F /Q %dummySoundFile% 2> nul
echo %dummySoundFileData%> %dummySoundFile%.tmp
certutil -f -decodehex %dummySoundFile%.tmp %dummySoundFile% >nul
del /F /Q %dummySoundFile%.tmp 2> nul
set templateFolder1=%testSoundFolder%\tmp_level1
set templateFolder2=%testSoundFolder%\tmp_level2
echo.
echo Creating template sound folder %templateFolder1%
mkdir %templateFolder1% 2> nul
set /A soundFilesCreated=0
echo.
for /l %%x in (1, 1, %soundCountPerFolder%) do (
set fx=000000%%x
set fx=!fx:~-5!
set /A soundFilesCreated=soundFilesCreated+1
set filename=dummy_!fx!.wav
set file=%templateFolder1%\!filename!
echo Creating template file: !file! ^(%%x / %soundCountPerFolder%^)
copy /B /Y %dummySoundFile% !file! /B 1> nul
)
echo.
echo Creating template sound folder %templateFolder2%
mkdir %templateFolder2% 2> nul
set /A soundDirsCopiedLevel1=0
echo.
for /l %%y in (1, 1, %soundCountFolderLevel1%) do (
set fy=000000%%y
set fy=!fy:~-5!
set /A soundDirsCopiedLevel1=soundDirsCopiedLevel1+1
set folder=%templateFolder2%\!fy!
mkdir !folder! 2> nul
echo Copying dir level 1: %templateFolder1% --^> !folder! ^(%%y / %soundCountFolderLevel1%^)
xcopy %templateFolder1% !folder! /E /C /I /Y /Q 1> nul
)
echo.
echo Copying sound content to %testSoundFolder%
echo.
set /A soundDirsCopiedLevel2=0
for /l %%z in (1, 1, %soundCountFolderLevel2%) do (
set fz=000000%%z
set fz=!fz:~-5!
set folder=%testSoundFolder%\!fz!
set /A soundDirsCopiedLevel2=soundDirsCopiedLevel2+1
mkdir !folder!
echo Copying dir level 2: %templateFolder2% --^> !folder! ^(%%z / %soundCountFolderLevel2%^)
xcopy %templateFolder2% !folder! /E /C /I /Y /Q 1> nul
)
del /F /Q %dummySoundFile% 2> nul
echo.
echo Deleted temp dummy sound file %dummySoundFile%
rd /S /Q %templateFolder1% 2> nul
echo Deleted tempplate sound folder %templateFolder1%
rd /S /Q %templateFolder2% 2> nul
echo Deleted tempplate sound folder %templateFolder2%
:FINISH
cd %basedir%
set /A soundFilesCreated=soundFilesCreated
set /A soundDirsCopiedLevel1=soundDirsCopiedLevel1
set /A soundDirsCopiedLevel2=soundDirsCopiedLevel2
set /A soundFilesCreated=%soundFilesCreated%*%soundDirsCopiedLevel1%*%soundDirsCopiedLevel2%
echo.
echo %soundFilesCreated% files created.
endlocal
echo Press any key to close.
pause > nul
@echo on
@exit /B 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment