Skip to content

Question about coroutine #103

@MoJI4yH

Description

@MoJI4yH

I tried to compare the work of the coroutines in golang and "may" library, using the example of simple code that does almost nothing except run these coroutines

In go

package main

import (
	"sync"
	"time"
)

func main() {
	var wg sync.WaitGroup
	start := time.Now();
	for i := 0; i <= 10000000; i++ {
		wg.Add(1);
		go func() {
			wg.Done()
		}()
	}
	wg.Wait()
	finish := time.Now();
	elapsed := finish.Sub(start)
	println(elapsed.Seconds())
}

and it take about 3-4 sec

but if i run this

#[macro_use]
extern crate may;

use std::time::{Instant};
use wg::WaitGroup;

fn main() {
    let wg = WaitGroup::new();

    let now = Instant::now();
    
    for _ in 0..10_000_000 {
    let co_wg = wg.add(1);
    go!(move || {
    co_wg.done();
    });
    }
    
    wg.wait();
    println!("{}", now.elapsed().as_secs());
}

it take about 60+ sec

maybe I don't understand something or "may" is not designed to run millions coroutines at one time

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions