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

Question about coroutine #103

Open
MoJI4yH opened this issue May 21, 2023 · 2 comments
Open

Question about coroutine #103

MoJI4yH opened this issue May 21, 2023 · 2 comments

Comments

@MoJI4yH
Copy link

MoJI4yH commented May 21, 2023

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

@MoJI4yH MoJI4yH changed the title Question about corutine Question about coroutine May 21, 2023
@Xudong-Huang
Copy link
Owner

Xudong-Huang commented May 27, 2023 via email

@Xudong-Huang
Copy link
Owner

I would support may::sync::WaitGroup and may::sync::Barrier in future release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants