{"id":25949762,"url":"https://github.com/jeffotoni/benchmark-gocache","last_synced_at":"2026-06-01T06:31:33.121Z","repository":{"id":279908632,"uuid":"940377457","full_name":"jeffotoni/benchmark-gocache","owner":"jeffotoni","description":"Benchmark Caches - gocache v1, v2..v9, freecache, go-cache","archived":false,"fork":false,"pushed_at":"2025-04-07T20:53:41.000Z","size":28,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-08T16:03:16.655Z","etag":null,"topics":["benchamark","benchmarking","benchmarks","go","go-cache","golang"],"latest_commit_sha":null,"homepage":"https://goquick.run","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jeffotoni.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-28T04:19:53.000Z","updated_at":"2025-05-17T04:41:23.000Z","dependencies_parsed_at":"2025-02-28T12:57:39.750Z","dependency_job_id":"2c41b1b1-f70b-4806-a107-79c13ee772d7","html_url":"https://github.com/jeffotoni/benchmark-gocache","commit_stats":null,"previous_names":["jeffotoni/benchmark-gocache"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jeffotoni/benchmark-gocache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeffotoni%2Fbenchmark-gocache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeffotoni%2Fbenchmark-gocache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeffotoni%2Fbenchmark-gocache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeffotoni%2Fbenchmark-gocache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jeffotoni","download_url":"https://codeload.github.com/jeffotoni/benchmark-gocache/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeffotoni%2Fbenchmark-gocache/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33763648,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-01T02:00:06.963Z","response_time":115,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["benchamark","benchmarking","benchmarks","go","go-cache","golang"],"created_at":"2025-03-04T12:29:03.559Z","updated_at":"2026-06-01T06:31:33.114Z","avatar_url":"https://github.com/jeffotoni.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![License](https://img.shields.io/github/license/jeffotoni/benchmark-gocache)](https://github.com/jeffotoni/benchmark-gocache/blob/main/LICENSE)\n![GitHub last commit](https://img.shields.io/github/last-commit/jeffotoni/benchmark-gocache)\n![GitHub forks](https://img.shields.io/github/forks/jeffotoni/benchmark-gocache?style=social)\n![GitHub stars](https://img.shields.io/github/stars/jeffotoni/benchmark-gocache)\n\n# 🚀💕 Benchmarks for Go In-Memory Caches\n\nThis repository provides a comprehensive benchmark suite comparing **nine custom cache implementations** from [`jeffotoni/gocache`](https://github.com/jeffotoni/gocache) (versions `v1` through `v9`), plus two well-known open-source libraries:\n\n- [`patrickmn/go-cache`](https://github.com/patrickmn/go-cache)\n- [`coocood/freecache`](https://github.com/coocood/freecache)\n\nAll tests are run on an **Apple M3 Max** machine (Darwin/arm64) to measure both **1-second** and **3-second** benchmark performance (`-benchtime=1s` and `-benchtime=3s`).\n\n## Why Use an In-Memory Cache?\n\n- **Faster Access**: In-memory caches reduce latency by storing frequently accessed data directly in memory, avoiding repeated database or external service calls.\n- **Reduced Load**: Caching lowers the workload on databases and APIs, improving overall system throughput.\n- **Quick Expiration**: In-memory caches are best for *ephemeral* data where occasional staleness is tolerable, and items can expire quickly.\n\n## Cache Implementations Tested\n\nWe benchmarked nine versions from [`jeffotoni/gocache`](https://github.com/jeffotoni/gocache), each using different concurrency strategies, expiration approaches, and internal data structures. Additionally, we tested:\n\n- **`go-cache`**: [patrickmn/go-cache](https://github.com/patrickmn/go-cache)\n- **`freecache`**: [coocood/freecache](https://github.com/coocood/freecache)\n\nBelow is a snippet showing how the caches are instantiated in our benchmarking suite:\n\n```go\nvar cacheV1 = v1.New(10 * time.Minute)\nvar cacheV2 = v2.New[string, int](10*time.Minute, 0)\nvar cacheV3 = v3.New(10*time.Minute, 1*time.Minute)\nvar cacheV4 = v4.New(10 * time.Minute)\nvar cacheV5 = v5.New(10 * time.Minute)\nvar cacheV6 = v6.New(10 * time.Minute)\nvar cacheV7 = v7.New(10 * time.Minute)\nvar cacheV8 = v8.New(10*time.Minute, 8)\nvar cacheV9 = v9.New(10 * time.Minute)\n\n// Third-party libraries\nvar cacheGoCache = gocache.New(10*time.Second, 1*time.Minute)\nvar fcacheSize = 100 * 1024 * 1024 // 100MB cache\nvar cacheFreeCache = freecache.NewCache(fcacheSize)\n```\n\nEach version of gocache implements different optimizations (locking, sharding, ring buffers, etc.) to analyze performance trade-offs.\n\nExample Benchmark Function\n\nBelow is an example benchmark test used for Version 1 (v1), focusing on both Set() and Get():\n\n```go\n//The result wiil BenchmarkGcacheSet1(b *testing.B)\nfunc BenchmarkGcacheSet1(b *testing.B) {\n\tfor i := 0; i \u003c b.N; i++ {\n\t\tkey := strconv.Itoa(i)\n\t\tcacheV1.Set(key, i, time.Duration(time.Minute))\n\t}\n}\n\n//The result wiil BenchmarkGcacheSetGet1(b *testing.B)\nfunc BenchmarkGcacheSetGet1(b *testing.B) {\n\tfor i := 0; i \u003c b.N; i++ {\n\t\tkey := strconv.Itoa(i)\n\t\tcacheV1.Set(key, i, 10*time.Minute)\n\t\ti, ok := cacheV1.Get(key)\n\t\tif !ok {\n\t\t\tlog.Printf(\"Not Found %v\", i)\n\t\t}\n\t}\n}\n...\n```\n\nNote: Similar benchmark functions are repeated for v2 through v9, plus go-cache and freecache.\n\n## Benchmark de Cache em Go  \n**Architecture:** Apple M3 Max (arm64)\n**Package:** `benchmark-gocache`\n\n```sh\n$ go test -bench=. -benchtime=5s -benchmem\n```\n\n# 📊 Go Cache Benchmark Comparison Freecache, Ristretto, Bigcache and Go-cache\n\nThis benchmark compares several Go in-memory caching libraries using `go test -bench` on an Apple M3 Max (arm64) CPU.  \nEach implementation is tested for raw **Set** performance and **Set/Get** combined performance.  \nThe values reflect **nanoseconds per operation**, **allocations**, and **bytes per op** under high concurrency (`GOMAXPROCS=16`).\n\n---\n\n| **Implementation**     | **Set Ops**     | **Set ns/op** | **Set/Get Ops** | **Set/Get ns/op** | **Observations**                                 |\n|------------------------|------------------|----------------|------------------|--------------------|--------------------------------------------------|\n| **gocache V1**         | 28,414,197       | 338.6 ns/op    | 22,687,808       | 294.9 ns/op        | Baseline version — decent speed, moderate allocs |\n| **gocache V8**         | 26,022,742       | 364.5 ns/op    | 15,105,789       | 393.6 ns/op        | High memory cost, TTL enabled                    |\n| **gocache V9**         | 44,026,141       | 265.4 ns/op    | 23,528,972       | 270.0 ns/op        | 🏆 **Fastest write throughput**                  |\n| **gocache V10**        | 19,749,439       | 393.2 ns/op    | 16,217,510       | 495.9 ns/op        | ❌ Higher allocation and latency                  |\n| **gocache V11 (Short)**| 39,719,458       | 264.2 ns/op    | 23,308,189       | 265.4 ns/op        | ⚡ Short TTL — very fast overall                  |\n| **gocache V11 (Long)** | 22,334,095       | 348.8 ns/op    | 18,338,124       | 319.7 ns/op        | Balanced long TTL setup                          |\n| **go-cache**           | 25,669,981       | 392.5 ns/op    | 20,485,022       | 306.0 ns/op        | Stable, but slower than newer gocache versions   |\n| **freecache**          | 41,543,706       | 380.3 ns/op    | 14,433,577       | 425.2 ns/op        | 🚀 Fast writes, significantly slower reads        |\n| **ristretto**          | 30,257,541       | 352.3 ns/op    | 10,055,701       | 547.8 ns/op        | 🧠 TinyLFU eviction, high allocation per op       |\n| **bigcache**           | 30,260,250       | 320.6 ns/op    | 14,382,721       | 354.6 ns/op        | 🔥 Very consistent, low GC overhead               |\n\n---\n\n### 🧠 Notes:\n\n- `gocache` is a custom in-memory cache optimized for concurrency, modularity, and optional TTL.\n- `freecache`, `go-cache`, `bigcache`, and `ristretto` are popular open-source libraries with different focuses (size control, expiration, LFU, etc).\n- **Set/Get** benchmarks include an immediate `Get()` call after each `Set()`.\n- Allocation and GC behavior differ drastically across libraries, especially with TTL and internal eviction mechanisms.\n\n---\n\n## 🚀 1-Second Benchmarks\n\n```sh\n$ go test -bench=. -benchtime=1s\n```\n\n| **Implementation** | **Set Ops**    | **Set ns/op** | **Set/Get Ops** | **Set/Get ns/op** | **Observations**                      |\n|--------------------|----------------|---------------|-----------------|-------------------|---------------------------------------|\n| **gocache V1**     | 6,459,714      | 259.4 ns/op   | 5,062,861       | 245.0 ns/op       | Fast reads, decent writes             |\n| **gocache V2**     | 6,597,314      | 239.5 ns/op   | 4,175,704       | 280.4 ns/op       | Good write speed, average read        |\n| **gocache V3**     | 7,094,665      | 259.7 ns/op   | 4,746,934       | 281.6 ns/op       | Balanced performance                  |\n| **gocache V4**     | 4,644,594      | 324.4 ns/op   | 3,571,759       | 330.9 ns/op       | ❌ Slower (sync.Map)                  |\n| **gocache V5**     | 6,311,216      | 252.6 ns/op   | 4,714,106       | 278.7 ns/op       | Solid all-around                      |\n| **gocache V6**     | 7,532,767      | 262.6 ns/op   | 4,865,896       | 256.2 ns/op       | 🔥 Great concurrency                  |\n| **gocache V7**     | 8,026,825      | 222.4 ns/op   | 4,978,083       | 244.3 ns/op       | 🏆 **Best write** (1s), fast reads    |\n| **gocache V8**     | 4,708,249      | 309.3 ns/op   | 2,513,566       | 399.7 ns/op       | ❌ Slower overall                     |\n| **gocache V9**     | 9,295,434      | 215.9 ns/op   | 5,096,511       | 272.7 ns/op       | 🏆 **Fastest write** (lowest ns/op)   |\n| **go-cache**       | 6,463,236      | 291.6 ns/op   | 4,698,109       | 290.7 ns/op       | Solid library, slower than V7/V9      |\n| **freecache**      | 5,803,242      | 351.1 ns/op   | 2,183,834       | 469.7 ns/op       | 🚀 Decent writes, poor reads          |\n\n## 🚀 3-Second Benchmarks\n\n```sh\n$ go test -bench=. -benchtime=3s\n```\n\n| **Implementation** | **Set Ops**     | **Set ns/op** | **Get Ops**     | **Get ns/op** | **Observations**                     |\n|--------------------|-----------------|---------------|-----------------|---------------|--------------------------------------|\n| **gocache V1**     | 17,176,026      | 338.5 ns/op   | 13,891,083      | 268.6 ns/op   | Fast read, solid write               |\n| **gocache V2**     | 16,457,449      | 318.5 ns/op   | 12,379,336      | 304.4 ns/op   | Good write speed, average read       |\n| **gocache V3**     | 20,858,042      | 310.8 ns/op   | 14,042,400      | 287.1 ns/op   | Balanced, efficient                  |\n| **gocache V4**     | 15,255,268      | 422.4 ns/op   | 8,882,214       | 406.3 ns/op   | ❌ Slow (sync.Map)                   |\n| **gocache V5**     | 20,500,326      | 348.9 ns/op   | 12,597,715      | 271.7 ns/op   | Good balance                         |\n| **gocache V6**     | 21,767,736      | 341.4 ns/op   | 13,085,462      | 297.3 ns/op   | 🔥 Strong concurrency                |\n| **gocache V7**     | 27,229,544      | 252.4 ns/op   | 14,574,768      | 268.6 ns/op   | 🏆 **Best write** (3s)               |\n| **gocache V8**     | 15,796,894      | 383.5 ns/op   | 8,927,028       | 408.8 ns/op   | ❌ Slower overall                    |\n| **gocache V9**     | 24,809,947      | 252.1 ns/op   | 13,225,228      | 275.7 ns/op   | 🏆 **Very fast write**, good read    |\n| **go-cache**       | 15,594,752      | 375.4 ns/op   | 14,289,182      | 269.7 ns/op   | 🚀 Excellent reads, slower writes    |\n| **freecache**      | 13,303,050      | 402.3 ns/op   | 8,903,779       | 421.4 ns/op   | ❌ Decent write, slow read           |\n\n## 🏅 Benchmark Icons Guide  \n\nThese icons indicate key **performance insights** from our benchmarks:  \n\n- 🏆 **Top Performance** → Best result in a specific category (fastest read/write).  \n- ❌ **Underperformance** → Notably slower compared to other implementations.  \n- 🔥 **Balanced \u0026 Scalable** → Strong concurrency, optimized trade-offs.  \n- 🚀 **High Speed** → Impressive performance, but not always the absolute fastest.  \n\n💡 Use these indicators to **quickly identify the strengths and weaknesses** of each cache version!  \n\n## 🚀 Key Highlights  \n\n✅ **Best Write Performance**:  \n   - 🏆 **V7 and V9** consistently deliver the **fastest writes** (`lowest ns/op` in Set benchmarks).  \n   - **V9** achieves top speeds while maintaining strong read performance.  \n\n✅ **Best Read Performance**:  \n   - **V1 and go-cache** often provide **the lowest `ns/op` in Get benchmarks**, making them excellent choices for read-heavy workloads.  \n   - **go-cache** remains a strong competitor in retrieval speed.  \n\n⚠️ **Slower Performance Observed**:  \n   - ❌ **V4 (`sync.Map`) and V8** struggle in both read and write speeds, making them less suitable for high-performance applications.  \n   - **freecache** performs well in **writes** but has significantly **slower read speeds**.  \n\n🔥 **Overall, V7 and V9 stand out as the best-balanced options for both write speed and retrieval performance!**  \n\n## ⚖️ Overall Trade-Offs  \n\nEvery cache implementation has **its own strengths and weaknesses**:  \n\n✅ **Optimized for Reads** → Some caches prioritize fast retrieval speeds.  \n🚀 **High Write Throughput** → Others are designed to handle massive insertions efficiently.  \n🔥 **Balanced Performance** → **V7 and V9** strike a great balance between **read and write speeds**.  \n\n💡 **Choosing the right cache depends on your workload needs!**  \n\n---\n\n## 🤝 Contributing  \n\nWant to **enhance this benchmark suite**? Follow these simple steps:  \n\n1️⃣ **Fork this repo** and add your own cache tests or custom versions.  \n2️⃣ **Submit a Pull Request (PR)** with your improvements or questions.  \n3️⃣ **Join the discussion** by opening an issue to suggest new features or optimizations.  \n\nYour contributions are always welcome! 🚀✨  \n\n---\n\n## 🔗 Related Projects  \n\nThis benchmark compares the following caching solutions:  \n\n✅ [**jeffotoni/gocache**](https://github.com/jeffotoni/gocache) – Custom high-performance cache versions (V1–V9).  \n✅ [**patrickmn/go-cache**](https://github.com/patrickmn/go-cache) – Lightweight in-memory cache with expiration.  \n✅ [**coocood/freecache**](https://github.com/coocood/freecache) – High-speed cache optimized for low GC overhead.  \n\n📌 If you know another cache worth benchmarking, feel free to suggest it!  \n\n---\n\n## 📜 License  \n\nThis project is **open-source** under the **MIT License**.  \n\n💡 Feel free to **fork, modify, and experiment** with these benchmarks in your own applications or libraries.  \n🔬 The goal is to **help developers choose the best in-memory cache** for their needs.  \n\n🚀 **Happy benchmarking!**","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeffotoni%2Fbenchmark-gocache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjeffotoni%2Fbenchmark-gocache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeffotoni%2Fbenchmark-gocache/lists"}