<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/performance-observations-on-a-c-vector-of-lambdas-xqng7piaz" -->

---
title: Performance observations on a C++ vector of lambdas
description: A benchmarking study comparing compile-time and runtime performance of storing C++ lambdas in a std::vector using two approaches: std::function<> and a...
canonical: https://daily.dev/posts/performance-observations-on-a-c-vector-of-lambdas-xqng7piaz
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Performance observations on a C++ vector of lambdas | daily.dev
og:description: A benchmarking study comparing compile-time and runtime performance of storing C++ lambdas in a std::vector using two approaches: std::function<> and a...
og:url: https://daily.dev/posts/performance-observations-on-a-c-vector-of-lambdas-xqng7piaz
og:image: https://api.daily.dev/og/posts/xqng7piaZ.png
og:image:alt: Performance observations on a C++ vector of lambdas
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Performance observations on a C++ vector of lambdas

**[Playful Programming](https://daily.dev/sources/playfulprogramming)** · 6 min read · 0 upvotes · 0 comments

## Summary

A benchmarking study comparing compile-time and runtime performance of storing C++ lambdas in a std::vector using two approaches: std::function<> and a hand-crafted virtual interface with std::unique_ptr<>. Key findings: std::function<> takes roughly 2-3x longer to compile than the custom interface approach, and with clang++3.6 using emplace_back() with optimizations enabled, compile time explodes to 338 seconds. At runtime, std::function<> is actually faster to call, likely due to better cache locality from small-buffer optimization. emplace_back() provides no meaningful runtime benefit over push_back() in this scenario, and actually hurts compile times significantly.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://playfulprogramming.com/posts/performance-observations-on-c-vector-of>

## Similar posts on daily.dev

- [The Cost Of a Closure in C](https://daily.dev/posts/the-cost-of-a-closure-in-c-8jkdqymxq) · The Pasture · 1 upvotes · 0 comments
- [Follow up: resize \+ assign is often faster than reserve \+ emplace\_back for vector](https://daily.dev/posts/follow-up-resize-assign-is-often-faster-than-reserve-emplace-back-for-vector-nusmzcdfu) · Meeting C\+\+ · 1 upvotes · 0 comments
- [Interconverting std::function and copyable\_function](https://daily.dev/posts/interconverting-std-function-and-copyable-function-az8s7dlex) · Arthur O'Dwyer · 0 upvotes · 0 comments
- [Beyond Virtual Functions: High-Performance Polymorphism with C\+\+17 std::variant and std::visit](https://daily.dev/posts/beyond-virtual-functions-high-performance-polymorphism-with-c-17-std-variant-and-std-visit-h29ex98g7) · Towards Dev · 0 upvotes · 0 comments
- [October 2, 2025](https://daily.dev/posts/october-2-2025-tst3d8uiy) · C\+\+ · 0 upvotes · 0 comments

---

Tags: [#c++](https://daily.dev/tags/c++), [#performance](https://daily.dev/tags/performance)

[View this post on daily.dev](https://daily.dev/posts/performance-observations-on-a-c-vector-of-lambdas-xqng7piaz)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Performance observations on a C++ vector of lambdas","url":"https://daily.dev/posts/performance-observations-on-a-c-vector-of-lambdas-xqng7piaz","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/performance-observations-on-a-c-vector-of-lambdas-xqng7piaz"},"datePublished":"2026-03-16T21:48:27.808Z","dateModified":"2026-10-14T02:30:21.884Z","description":"A benchmarking study comparing compile-time and runtime performance of storing C++ lambdas in a std::vector using two approaches: std::function\u003c\u003e and a...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/6bca21e628fe69fc9f4bc6a3d6a92689?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/6bca21e628fe69fc9f4bc6a3d6a92689?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Playful Programming","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Playful Programming","logo":"https://media.daily.dev/image/upload/s--WoGOmY81--/f_auto,q_auto/v1773697582/logos/playfulprogramming?_a=BAMAMiiu0","url":"https://daily.dev/sources/playfulprogramming"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/performance-observations-on-a-c-vector-of-lambdas-xqng7piaz","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"c++,performance","timeRequired":"PT6M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Playful Programming","item":"https://daily.dev/sources/playfulprogramming"},{"@type":"ListItem","position":3,"name":"Performance observations on a C++ vector of lambdas"}]}
```

