Skip to content

Instantly share code, notes, and snippets.

@zamabuvaraeu
Created April 27, 2024 10:08
Show Gist options
  • Save zamabuvaraeu/9dc6af4eba8d2bce68dcce9d2927317c to your computer and use it in GitHub Desktop.
Save zamabuvaraeu/9dc6af4eba8d2bce68dcce9d2927317c to your computer and use it in GitHub Desktop.
Измерение производительности менеджеров памяти
#include once "crt.bi"
#include once "windows.bi"
#include once "win\ole2.bi"
Const PAGE_SIZE = 4096
Const ElapsedCount = 10
Const RepeatsCount = 5000000
Type ElapsedsVector
vec(0 To (ElapsedCount - 1)) As Double
End Type
Scope
Print "test Allocate"
Dim Elapseds As ElapsedsVector = Any
For j As Integer = 0 To ElapsedCount - 1
Dim t As Double = Timer()
For i As Integer = 0 To RepeatsCount - 1
Dim cbBytes As UInteger = rand()
Dim cbMemSize As UInteger = (cbBytes Mod (PAGE_SIZE - 265))
Dim pMem As Integer Ptr = Allocate(cbMemSize)
If pMem = 0 Then
End(1)
End If
Deallocate(pMem)
Next
Elapseds.vec(j) = Timer() - t
Print Elapseds.vec(j)
Next
Dim Sum As Double
For j As Long = 0 To ElapsedCount - 1
Sum += Elapseds.vec(j)
Next
Dim Average As Double = Sum / ElapsedCount
Print "Average", Average
End Scope
Scope
Print "test HeapAlloc"
Dim hHeap As Handle = GetProcessHeap()
Dim Elapseds As ElapsedsVector = Any
For j As Integer = 0 To ElapsedCount - 1
Dim t As Double = Timer()
For i As Integer = 0 To RepeatsCount - 1
Dim cbBytes As UInteger = rand()
Dim cbMemSize As UInteger = (cbBytes Mod (PAGE_SIZE - 265))
Dim pMem As Integer Ptr = HeapAlloc(hHeap, 0, cbMemSize)
If pMem = 0 Then
End(1)
End If
HeapFree(hHeap, 0, pMem)
Next
Elapseds.vec(j) = Timer() - t
Print Elapseds.vec(j)
Next
Dim Sum As Double
For j As Long = 0 To ElapsedCount - 1
Sum += Elapseds.vec(j)
Next
Dim Average As Double = Sum / ElapsedCount
Print "Average", Average
End Scope
Scope
Print "test Private HeapAlloc"
Dim hHeap As Handle = HeapCreate(HEAP_NO_SERIALIZE, PAGE_SIZE * 4, 0)
Dim Elapseds As ElapsedsVector = Any
For j As Integer = 0 To ElapsedCount - 1
Dim t As Double = Timer()
For i As Integer = 0 To RepeatsCount - 1
Dim cbBytes As UInteger = rand()
Dim cbMemSize As UInteger = (cbBytes Mod (PAGE_SIZE - 265))
Dim pMem As Integer Ptr = HeapAlloc(hHeap, HEAP_NO_SERIALIZE, cbMemSize)
If pMem = 0 Then
End(1)
End If
HeapFree(hHeap, HEAP_NO_SERIALIZE, pMem)
Next
Elapseds.vec(j) = Timer() - t
Print Elapseds.vec(j)
Next
Dim Sum As Double
For j As Long = 0 To ElapsedCount - 1
Sum += Elapseds.vec(j)
Next
Dim Average As Double = Sum / ElapsedCount
Print "Average", Average
End Scope
Scope
Print "test CoTaskMemAlloc"
Dim Elapseds As ElapsedsVector = Any
For j As Integer = 0 To ElapsedCount - 1
Dim t As Double = Timer()
For i As Integer = 0 To RepeatsCount - 1
Dim cbBytes As UInteger = rand()
Dim cbMemSize As UInteger = (cbBytes Mod (PAGE_SIZE - 265))
Dim pMem As Integer Ptr = CoTaskMemAlloc(cbMemSize)
If pMem = 0 Then
End(1)
End If
CoTaskMemFree(pMem)
Next
Elapseds.vec(j) = Timer() - t
Print Elapseds.vec(j)
Next
Dim Sum As Double
For j As Long = 0 To ElapsedCount - 1
Sum += Elapseds.vec(j)
Next
Dim Average As Double = Sum / ElapsedCount
Print "Average", Average
End Scope
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment