Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add hashmaps #6

Merged
merged 35 commits into from
Sep 15, 2024
Merged
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
598f765
feat: add hashmaps
Dec 21, 2023
aa8319e
feat: add docs
joetifa2003 Mar 28, 2024
3c45a26
feat: use hashstructure for hashmaps
joetifa2003 Apr 3, 2024
e21dc7f
feat: use maphash instead of hashstructure
joetifa2003 Sep 7, 2024
f01ba03
fix: use CGO instead of purgo
joetifa2003 Sep 7, 2024
e86ecfb
feat: allocator interface
joetifa2003 Sep 7, 2024
9e0ab5f
feat: batch allocation
joetifa2003 Sep 7, 2024
62cdfdc
feat: refactor hashmap to use allocator interface
joetifa2003 Sep 7, 2024
0e0bd60
feat: linked list allocator interface
joetifa2003 Sep 7, 2024
30e991a
feat: add minheap datastructure
joetifa2003 Sep 7, 2024
fc821f4
feat: refactor vectors to use allocator interface
joetifa2003 Sep 7, 2024
17c5841
fix: remove purgo as dependency
joetifa2003 Sep 7, 2024
c829387
feat: refactor mmstring to use allocator
joetifa2003 Sep 7, 2024
c99b046
feat: refactor typedarena to use allocator
joetifa2003 Sep 7, 2024
ec0bd39
fix: add Realloc to allocator package and fix a bug in vector
joetifa2003 Sep 7, 2024
546e393
fix: freeing wrong ptr in realloc
joetifa2003 Sep 7, 2024
e8cb98e
fix: migrate tests to new allocator
joetifa2003 Sep 7, 2024
fca9501
fix: remove old malloc package and old helpers, moving too allocator …
joetifa2003 Sep 7, 2024
b393c26
chore: separate typedarena benchmark
joetifa2003 Sep 7, 2024
5ed42a2
feat: update to go 1.23
joetifa2003 Sep 7, 2024
06b6e95
feat: batch allocator alignment
joetifa2003 Sep 8, 2024
88a1ff2
feat: heavily refactor batch allocator
joetifa2003 Sep 8, 2024
cb5094b
feat: add UnsafeAt and use it in MinHeap
joetifa2003 Sep 8, 2024
dfbd530
feat: experimenting with new benchmarks
joetifa2003 Sep 8, 2024
ea9dfd7
feat: optimize performance of allocator helpers
joetifa2003 Sep 8, 2024
de16911
feat: add typed arena to benchmark
joetifa2003 Sep 8, 2024
07582e7
chore: rename c allocator
joetifa2003 Sep 9, 2024
f5dc88e
feat: update readme
joetifa2003 Sep 10, 2024
bc6ab38
feat: docs and update README
joetifa2003 Sep 14, 2024
d4655b6
fix: reallocate example
joetifa2003 Sep 14, 2024
addfc4c
feat: update iterators
joetifa2003 Sep 15, 2024
39e3ffb
feat: more examples
joetifa2003 Sep 15, 2024
c9157ad
feat: update documentation
joetifa2003 Sep 15, 2024
9c97729
feat: add a quick intorduction
joetifa2003 Sep 15, 2024
3d6b57b
feat: update benchmarks
joetifa2003 Sep 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: add typed arena to benchmark
  • Loading branch information
joetifa2003 committed Sep 8, 2024
commit de16911630ccafb1342c28872d47cfa173b16fbf
43 changes: 42 additions & 1 deletion mm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/joetifa2003/mm-go"
"github.com/joetifa2003/mm-go/allocator"
"github.com/joetifa2003/mm-go/batchallocator"
"github.com/joetifa2003/mm-go/typedarena"
)

type Node[T any] struct {
Expand Down Expand Up @@ -47,14 +48,27 @@ func linkedListPushAlloc[T any](alloc allocator.Allocator, list *LinkedList[T],
}
}

func linkedListPushArena[T any](arena *typedarena.TypedArena[Node[T]], list *LinkedList[T], value T) {
node := arena.Alloc()
node.value = value

if list.head == nil {
list.head = node
list.tail = node
} else {
list.tail.next = node
node.prev = list.tail
list.tail = node
}
}

func linkedListFree[T any](alloc allocator.Allocator, list *LinkedList[T]) {
currentNode := list.head
for currentNode != nil {
nextNode := currentNode.next
allocator.Free(alloc, currentNode)
currentNode = nextNode
}
allocator.Free(alloc, list)
}

const LINKED_LIST_SIZE = 10000
Expand Down Expand Up @@ -82,6 +96,33 @@ func BenchmarkLinkedListBatchAllocator(b *testing.B) {
}
}

func BenchmarkLinkedListTypedArena(b *testing.B) {
for _, chunkSize := range []int{100, 200, 500, LINKED_LIST_SIZE} {
b.Run(fmt.Sprintf("chunk size %d", chunkSize), func(b *testing.B) {
for range b.N {
benchLinkedListTypedArena(b, LINKED_LIST_SIZE, chunkSize)
}
})
}
}

func benchLinkedListTypedArena(b *testing.B, size int, chunkSize int) {
alloc := allocator.NewCallocator()
defer alloc.Destroy()

arena := typedarena.New[Node[int]](alloc, chunkSize)
defer arena.Free()

list := allocator.Alloc[LinkedList[int]](alloc)
defer allocator.Free(alloc, list)

for i := range size {
linkedListPushArena(arena, list, i)
}

assertLinkedList(b, list)
}

func benchLinkedListManaged(b *testing.B, size int) {
list := &LinkedList[int]{}
for i := range size {
Expand Down
Loading