Sitemap

Performance Comparison : Coroutines(Kotlin) Vs Multithreading(Java) Vs Goroutines(Go)

2 min readApr 2, 2025

--

Asynchronous programming plays a key role in building real-time applications. In this article, we will compare the Asynchronous programming paradigms from Kotlin, Java and Go.

What is Asynchronous Programming?

Asynchronous programming is a technique that allows a program to continue other tasks while waiting for a long running operation to be completed.

Why do we need Asynchronous Programming?

While building real time applications we often come across situations where one operation takes a lot of time. Due to this hold up, execution of other operations is held up too. To best make use of the resources and time, we user Asynchronous Programming, i.e Concurrency.

In this article, we will compare the Asynchronous programming techniques from Java, Kotlin and Go.

Let us check the performance with an experiment. Here we are trying to run each program in the respective languages where each implementation performs a task, that is sleeping for 1 second in multiple concurrent executions.

Here are the examples from each language.

Kotlin:

import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlin.system.measureTimeMillis

fun main() = runBlocking{
val time = measureTimeMillis {
val jobs = List(1000){
launch {
delay(1000L)
}
}

jobs.forEach { it.join() }
}

println("Kotlin coroutines took : $time ms")
}

Java:

import java.util.ArrayList;
import java.util.List;

public class main {
public static void main(String[] args) {
long start = System.currentTimeMillis();

List<Thread> threadList = new ArrayList<>();
for (int i = 0; i < 1000; i++) {
Thread thread = new Thread(() -> {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
});
thread.start();
threadList.add(thread);
}

for (Thread thread : threadList) {
try {
thread.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}

long timeTaken = System.currentTimeMillis() - start;
System.out.println(STR."Java Threads took $\{timeTaken} ms");
}
}

Go:

package main

import (
"fmt"
"sync"
"time"
)

func worker(wg *sync.WaitGroup) {
defer wg.Done()
time.Sleep(1 * time.Second) // Simulating work
}

func main() {
var wg sync.WaitGroup
start := time.Now()

wg.Add(1000)
for i := 0; i < 1000; i++ {
go worker(&wg)
}
wg.Wait()

fmt.Printf("Go Goroutines took %v ms\n", time.Since(start).Milliseconds())
}

NOTE: The performance totally depends on the machine which is used to conduct this experiment.

From above blocks of code, you can observe that all the programs are trying to achieve the same thing.

******RESULTS********:

Kotlin: ~1122 ms, Go: ~1000 ms, Java : ~1245ms

There you have it. Comparing based on the time taken, Go took the least amount of time to complete the tasks using Goroutines. This is due to Go’s runtime optimizations. Also, Goroutines are much lighter compared to Kotlin’s Coroutines and Java’s Threads.

--

--

Aahlad kethineedi
Aahlad kethineedi

Written by Aahlad kethineedi

Software Developer. I enjoy reading about Tech and Finance.