LogRoutine

개요[ | ]

LogRoutine
package main

import (
	"fmt"
	"os"
	"strconv"
	"sync"
	"time"

	"github.com/google/uuid"
)

func main() {
	numLogs := 10
	if envNumLogs, exists := os.LookupEnv("NUM_LOGS"); exists {
		if parsedNumLogs, err := strconv.Atoi(envNumLogs); err == nil {
			numLogs = parsedNumLogs
		} else {
			fmt.Printf("Invalid NUM_LOGS value, using default: %d\n", numLogs)
		}
	}
	prefix := fmt.Sprintf("LogRoutine %s", uuid.New().String()[:8])

	var wg sync.WaitGroup
	startTime := time.Now()
	for i := 1; i <= numLogs; i++ {
		wg.Add(1)
		go func(index int) {
			defer wg.Done()
			fmt.Println(prefix, index)
		}(i)
	}
	wg.Wait()
	elapsedTime := time.Since(startTime)

	fmt.Println("LogRoutine elapsed", elapsedTime)
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}