REM Filewrite performance benchmark 03-dec-2016 REM Test specification: REM Files written to contain random bytes FILESTOWRITE% = 100 FILESIZE% = 1000000 BUFFSIZE% = 1000 REM Only used with the fast method REM ------------------------------ REM!WC CRYPT_SILENT = 64 PROV_RSA_FULL = 1 DIM Buff% BUFFSIZE%+1 hProvider% = 0 REM ------------------------------ REM IF 1 runs the simple version, IF 0 runs the faster one IF 0 THEN Start=TIME REM 30.96 sec FOR I% = 1 TO FILESTOWRITE% f = OPENOUT("f"+STR$(I%)+".dum") FOR Cnt%=1 TO FILESIZE% BPUT#f,RND(256)-1 NEXT CLOSE#f NEXT ELSE REM Making bufsize larger further reduces the time. Bufsize = 10000 gives 1.78 sec Start=TIME REM 2.75 sec SYS "GetModuleHandle", "ADVAPI32" TO ADV% SYS "GetProcAddress", ADV%, "CryptGenRandom" TO `CryptGenRandom` SYS "GetModuleHandle", "KERNEL32" TO K32% SYS "GetProcAddress", K32%, "WriteFile" TO `WriteFile` IF FN_GetContext = 0 PRINT "No context": END FOR I% = 1 TO FILESTOWRITE% f = OPENOUT("f"+STR$(I%)+".dum") C% = FILESIZE% B% = BUFFSIZE% WHILE C% > 0 IF C% < B% B%=C% IF FN_RandData(B%) = 0 PRINT "Data failed": END SYS `WriteFile`, @hfile%(f), Buff%, B%, ^temp%, 0 C% -= B% ENDWHILE CLOSE#f NEXT PROC_RelContext SYS "FreeLibrary", ADV% SYS "FreeLibrary", K32% ENDIF PRINT TIME-Start END DEF FN_GetContext LOCAL res% SYS "CryptAcquireContext", ^hProvider%, 0, 0, PROV_RSA_FULL, CRYPT_SILENT TO res% = res% REM NOTE: The last 2 params to CryptAcquireContext are really: PROV_RSA_FULL, CRYPT_VERIFY_CONTEXT OR CRYPT_SILENT REM CRYPT_VERIFY_CONTEXT = 0, CRYPT_SILENT = 0x40, PROV_RSA_FULL = 1 DEF PROC_RelContext SYS "CryptReleaseContext", hProvider%, 0 ENDPROC DEF FN_RandData(nbytes%) LOCAL res% SYS `CryptGenRandom`, hProvider%, nbytes%, Buff% TO res% = res%