frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

C++ ranges/views vs. Rust iterator

2•bijan7•1h ago
it seems there is a quite a bit of gap between the performance of Rust iterator and C++ ranges/views unless I am missing something.

https://godbolt.org/z/v76rcEb9n https://godbolt.org/z/YG1dv4qYh

Rust: <code> use std::time::Instant;

fn expand_iota_views(input: &[i32]) -> impl Iterator<Item = i32> + '_ { input .iter() .flat_map(|&n| 1..=n) .flat_map(|n| 1..=n) .flat_map(|n| 1..=n) }

fn main() { let input: Vec<i32> = (0..=50).collect();

    let sample_result: Vec<i32> = expand_iota_views(&input).collect();
    println!("Rust Result count: {}", sample_result.len());

    let start = Instant::now();
    let mut total_count = 0;
    for _ in 0..1000 {
        let result = expand_iota_views(&input);
        total_count += result.count();
    }
    let duration = start.elapsed();

    println!("Rust Total count (1000 iterations): {}", total_count);
    println!("Rust Total time: {} microseconds", duration.as_micros());
    println!(
        "Rust Average per iteration: {:.2} microseconds",
        duration.as_micros() as f64 / 1000.0
    );
} </code>

Output: Rust Result count: 292825 Rust Total count (1000 iterations): 292825000 Rust Total time: 1025 microseconds Rust Average per iteration: 1.02 microseconds

C++: <code> #include <chrono> #include <iostream> #include <numeric> #include <ranges> #include <vector>

inline auto expandIotaViews(const std::vector<int>& input) { auto iota_transform = [](const int number) { return std::views::iota(1, number + 1); };

    return input 
                | std::views::transform(iota_transform) 
                | std::views::join 
                | std::views::transform(iota_transform) 
                | std::views::join
                | std::views::transform(iota_transform) 
                | std::views::join;
}

int main() { std::vector<int> input(51); std::iota(input.begin(), input.end(), 0);

    auto sample_result = expandIotaViews(input);
    std::vector<int> result_vec;
    for (auto val : sample_result) {
        result_vec.push_back(val);
    }

    std::cout << "C++ Result count: " << result_vec.size() << std::endl;

    auto start = std::chrono::high_resolution_clock::now();
    size_t total_count = 0;
    for (int i = 0; i < 1000; ++i) {
        auto result = expandIotaViews(input);
        total_count += std::ranges::distance(result);
    }
    auto end = std::chrono::high_resolution_clock::now();
    auto duration =
        std::chrono::duration_cast<std::chrono::microseconds>(end - start);

    std::cout << "C++ Total count (1000 iterations): " << total_count
              << std::endl;
    std::cout << "C++ Total time: " << duration.count() << " microseconds"
              << std::endl;
    std::cout << "C++ Average per iteration: " << duration.count() / 1000.0
              << " microseconds" << std::endl;

    return 0;
} </code>

Output: C++ Result count: 292825 C++ Total count (1000 iterations): 292825000 C++ Total time: 174455 microseconds C++ Average per iteration: 174.455 microseconds

Magical Systems Thinking

https://www.worksinprogress.news/p/magical-systems-thinking
1•komape•23s ago•0 comments

Tips and Shortcuts for Better Browsing

https://www.google.com/chrome/tips/
1•kamaraju•33s ago•0 comments

Boring Is Good

https://jenson.org/boring/
1•zdw•3m ago•0 comments

In Memory of Mat Travizano

https://maraoz.com/mat/
2•wslh•6m ago•0 comments

Simplaix – Agent-first project management and workflow automation

https://simplaix.com/
1•hanyuan_peng•7m ago•1 comments

I made an AI expense tracker because I don't like typing

https://apps.apple.com/us/app/xpendai-track-your-expenses/id6752033430
1•bruuuuuuuuh•7m ago•0 comments

turdus merula — iOS downgrade tool for A9-A10X devices

https://sep.lol/
2•Lammy•8m ago•0 comments

White House Plans Broad Crackdown on Liberal Groups

https://www.nytimes.com/2025/09/15/us/politics/jd-vance-charlie-kirk-show.html
2•hughw•8m ago•0 comments

Repairing sequential consistency in C/C++11 [pdf]

https://plv.mpi-sws.org/scfix/full.pdf
3•fanf2•12m ago•0 comments

Free Startup Ideas

https://www.minimumviablenl.com/
1•minimumviable•13m ago•0 comments

Robinhood plans to launch a startups fund open to all retail investors

https://techcrunch.com/2025/09/15/robinhood-plans-to-launch-a-startups-fund-open-to-all-retail-in...
2•jaredwiener•17m ago•0 comments

Europe Is a Terrified Child

https://davekeating.substack.com/p/europe-is-an-abused-child
6•ironyman•18m ago•0 comments

The Adventures of Reemo Green [video]

https://www.youtube.com/watch?v=5bYA2Rv2CQ8
1•tantalor•20m ago•0 comments

Field-Programmable Logic 2025 Best Paper Awards and FPL Community Award

https://2025.fpl.org/program/best-paper-awards/
2•gnabgib•20m ago•0 comments

Godot 4.5, making dreams accessible – Godot Engine

https://godotengine.org/releases/4.5/
4•makepanic•22m ago•1 comments

ChatPerson, our new RI (real intelligence) service

https://www.mcsweeneys.net/articles/introducing-chatperson
2•Geekette•23m ago•1 comments

What problems are worth solving?

5•KopyWasTaken•23m ago•0 comments

Rustlantis: Randomized Differential Testing of the Rust Compiler

https://plf.inf.ethz.ch/research/oopsla24-rustlantis.html
4•mooreds•26m ago•0 comments

Deaths are projected to exceed births in 2031

https://www.cbo.gov/publication/61390
7•johntfella•26m ago•0 comments

CLion Introduces Constexpr Debugger

https://blog.jetbrains.com/clion/2025/09/introducing-constexpr-debugger/
2•vitaut•26m ago•0 comments

Show HN: Blocks – Dream work apps and AI agents in minutes

https://blocks.diy
3•shelly_•28m ago•0 comments

Stategraph – Terraform without the state file bottleneck

https://stategraph.dev
1•lawnchair•28m ago•0 comments

Widespread Data Theft Targets Salesforce Instances via Salesloft Drift

https://cloud.google.com/blog/topics/threat-intelligence/data-theft-salesforce-instances-via-sale...
1•mooreds•28m ago•0 comments

Ghost Kitchens Are Dying. Here's the $15B Lesson Every Restaurateur Must Learn

https://davidrmann3.substack.com/p/ghost-kitchens-are-dying-heres-the
4•mooreds•29m ago•2 comments

The importance of sandboxing and access control in AI agents

https://gr1m0ire.xyz/articles/sandboxing_ai_agents
1•gemini-15•29m ago•0 comments

Elon Musk Promises Full Self-Driving "Next Year" [2014-2024]

https://www.youtube.com/watch?v=B4rdISpXigM
10•JumpinJack_Cash•33m ago•0 comments

One-Third of the Internet Is Bots Now

https://www.vice.com/en/article/yep-one-third-of-the-internet-is-just-bots-now/
7•bookofjoe•35m ago•1 comments

Nano BiBi – a free, AI creation platform powered by Google's Nano Banana

https://nanobibi.com/en
2•jokera•36m ago•1 comments

Show HN: Httpjail – HTTP(s) request filter for processes

https://github.com/coder/httpjail
3•ammario•36m ago•0 comments

I wrote an algorithm that matches you with an IRL group of nearby friends

https://klatchmaker.com/
2•v_dixon•37m ago•1 comments