This repository contains a Go program that demonstrates the difference between synchronous and asynchronous fetching of data. It showcases how asynchronous fetching using goroutines and channels can lead to faster execution times compared to synchronous fetching. 🌐⏰
The program consists of two main parts:
- Synchronous Fetching: Fetches mock user data (username, likes, and match) sequentially using synchronous function calls.
- Asynchronous Fetching: Fetches mock user data concurrently using goroutines and channels, allowing for parallel execution.
The program measures the execution time for both approaches and displays the fetched data along with the time taken.
Here are the typical results obtained from running the program:
As you can see, asynchronous fetching generally takes less time compared to synchronous fetching, as it allows for concurrent execution of the data fetching tasks. 🚀💨
The repository also includes a main_test.go
file that contains benchmark functions to measure the performance of synchronous and asynchronous fetching. To run the benchmarks, use the following command:
go test -bench=.
The benchmark results will provide insights into the performance difference between the two approaches, including the number of iterations, average time per iteration, and memory allocations. 📈
To run the program, follow these steps:
- Make sure you have Go installed on your system. 🐹
- Clone this repository:
git clone https://github.com/skapskap/go-concurrency
. 📥 - Navigate to the project directory:
cd go-concurrency
. 📂 - Run the program:
go run main.go
.▶️
You should see the fetched user data and the execution times for both synchronous and asynchronous fetching. ⏱️
Contributions to this repository are welcome! If you have any ideas, improvements, or bug fixes, feel free to open an issue or submit a pull request. Let's make this program even better together! 😄
This project is licensed under the MIT License. Feel free to use, modify, and distribute the code as per the terms of the license. 📜
Happy coding! 💻✨