add a scanner, but this seems to be a wrong solution. Change open-source head
This commit is contained in:
@@ -1,30 +1,10 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="TlsfAllocatorBench"
|
||||
// -----------------------------------------------------------------------------
|
||||
// file="HlsfAllocatorBench"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// Copyright (c) Nitload.
|
||||
// SPDX-License-Identifier: MIT
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using StgSharp.HighPerformance.Memory;
|
||||
using System;
|
||||
@@ -72,14 +52,6 @@ namespace StgSharp.Benchmark
|
||||
_libcLocalList.TrimExcess();
|
||||
}
|
||||
|
||||
[Benchmark(OperationsPerInvoke = TotalOperationsPerInvoke)]
|
||||
public void Tlsf()
|
||||
{
|
||||
for (int batch = 0; batch < BatchCount; batch++) {
|
||||
RunTlsf(batch, _tlsfAllocator, 4);
|
||||
}
|
||||
}
|
||||
|
||||
[IterationCleanup]
|
||||
public void IterationCleanup()
|
||||
{
|
||||
@@ -108,6 +80,14 @@ namespace StgSharp.Benchmark
|
||||
}
|
||||
}
|
||||
|
||||
[Benchmark(OperationsPerInvoke = TotalOperationsPerInvoke)]
|
||||
public void Tlsf()
|
||||
{
|
||||
for (int batch = 0; batch < BatchCount; batch++) {
|
||||
RunTlsf(batch, _tlsfAllocator, 4);
|
||||
}
|
||||
}
|
||||
|
||||
private static uint AlignSize(
|
||||
uint size
|
||||
)
|
||||
@@ -150,27 +130,6 @@ namespace StgSharp.Benchmark
|
||||
return (nuint)mb * 1024u * 1024u;
|
||||
}
|
||||
|
||||
private void RunTlsf(
|
||||
int batch,
|
||||
TwoLayerSegregatedFitAllocator allocator,
|
||||
int scanWindow = 4
|
||||
)
|
||||
{
|
||||
int batchOffset = batch * AllocationCount;
|
||||
_tlsfLocalList.Clear();
|
||||
|
||||
for (int i = 0; i < AllocationCount; i++)
|
||||
{
|
||||
uint size = _requestSizesByBatch[batchOffset + i];
|
||||
Tlsf.Handle allocate = allocator.Alloc(size);
|
||||
_tlsfLocalList.Add(allocate);
|
||||
}
|
||||
|
||||
for (int i = 0; i < _tlsfLocalList.Count; i++) {
|
||||
allocator.Free(_tlsfLocalList[_freeOrderByBatch[batchOffset + i]], scanWindow);
|
||||
}
|
||||
}
|
||||
|
||||
private unsafe void RunLibc(
|
||||
int batch
|
||||
)
|
||||
@@ -193,6 +152,27 @@ namespace StgSharp.Benchmark
|
||||
}
|
||||
}
|
||||
|
||||
private void RunTlsf(
|
||||
int batch,
|
||||
TwoLayerSegregatedFitAllocator allocator,
|
||||
int scanWindow = 4
|
||||
)
|
||||
{
|
||||
int batchOffset = batch * AllocationCount;
|
||||
_tlsfLocalList.Clear();
|
||||
|
||||
for (int i = 0; i < AllocationCount; i++)
|
||||
{
|
||||
uint size = _requestSizesByBatch[batchOffset + i];
|
||||
Tlsf.Handle allocate = allocator.Alloc(size);
|
||||
_tlsfLocalList.Add(allocate);
|
||||
}
|
||||
|
||||
for (int i = 0; i < _tlsfLocalList.Count; i++) {
|
||||
allocator.Free(_tlsfLocalList[_freeOrderByBatch[batchOffset + i]], scanWindow);
|
||||
}
|
||||
}
|
||||
|
||||
private void ShuffleFreeOrder(
|
||||
int offset,
|
||||
int count
|
||||
|
||||
Reference in New Issue
Block a user