Fundamentals 8 min read

Which Language Prints Hello World the Fastest? A Cross‑Language Comparison

This article explores the history and cultural significance of the "Hello World" program, presents concise implementations across dozens of programming languages, and compares their execution times in a single‑core sandbox, highlighting Bash as the quickest and Kotlin as the slowest.

21CTO
21CTO
21CTO
Which Language Prints Hello World the Fastest? A Cross‑Language Comparison

Hello World Overview

The "Hello World" program is the canonical first example used to illustrate the basic syntax of a programming language. It consists of a single statement that prints the text "Hello World!" to the screen, making it a convenient sanity‑check for a newly configured development environment.

Historical Significance

The tradition dates back to the 1970s, originating in the B language and popularized by Brian Kernighan and Dennis Ritchie in the 1978 book The C Programming Language . Because the example is minimal yet complete, it has been adopted by virtually every major language as a pedagogical staple.

Implementations in Various Languages

Bash

#!/bin/bash

greet() {
    echo "Hello, $1!"
}

greet "World"

C

#include <stdio.h>

void greet(const char *name) {
    printf("Hello, %s!
", name);
}

int main() {
    greet("World");
    return 0;
}

C#

using System;

public class Greeter {
    public static void Greet(string name) {
        Console.WriteLine($"Hello, {name}!");
    }
    public static void Main(string[] args) {
        Greet("World");
    }
}

C++

#include <iostream>
#include <string>

void greet(const std::string& name) {
    std::cout << "Hello, " << name << "!" << std::endl;
}

int main() {
    greet("World");
    return 0;
}

Dart

void greet(String name) {
  print('Hello, $name!');
}

void main() {
  greet('World');
}

Elixir

defmodule Greeter do
  def greet(name) do
    IO.puts("Hello, #{name}!")
  end
end

Greeter.greet("World")

Go

package main

import "fmt"

func greet(name string) {
    fmt.Printf("Hello, %s!
", name)
}

func main() {
    greet("World")
}

Haskell

greet :: String -> IO ()
greet name = putStrLn ("Hello, " ++ name ++ "!")

main :: IO ()
main = greet "World"

Java

public class Main {
    public static void greet(String name) {
        String msg = String.format("Hello, %s!", name);
        System.out.println(msg);
    }
    public static void main(String[] args) {
        greet("World");
    }
}

JavaScript

const greet = (name) => {
    console.log(`Hello, ${name}!`);
};

greet("World");

Kotlin

fun greet(name: String) {
    println("Hello, $name!")
}

fun main() {
    greet("World")
}

Lua

function greet(name)
    print("Hello, " .. name .. "!")
end

greet("World")

Odin

package main
import "core:fmt"

greet :: proc(name: string) {
    fmt.printf("Hello, %s!
", name)
}

main :: proc() {
    greet("World")
}

PHP

<?php
function greet($name) {
    echo "Hello, $name!";
}

greet("World");
?>

Python

def greet(name):
    print(f"Hello, {name}!")

greet("World")

R

greet <- function(name) {
  cat("Hello,", name, "!
")
}

greet("World")

Ruby

def greet(name)
  puts "Hello, #{name}!"
end

greet("World")

Rust

fn greet(name: &str) {
    println!("Hello, {}!", name);
}

fn main() {
    greet("World");
}

Swift

func greet(_ name: String) {
    print("Hello, \(name)!")
}

greet("World")

V

fn greet(name string) {
    println('Hello, ${name}!')
}

fn main() {
    greet('World')
}

Zig

const std = @import("std");

pub fn greet(name: []const u8) void {
    std.debug.print("Hello, {s}!
", .{name});
}

pub fn main() void {
    greet("World");
}

Performance Comparison

A benchmark executed in a single‑core container on an older CPU measured the time required for each language to run its "Hello World" program. Bash completed in under 0.4 seconds, while Kotlin took the longest at approximately 8.4 seconds.

Conclusion

The "Hello World" program remains more than a trivial example; it serves as a rite of passage for new developers and a quick sanity check for experienced programmers. Its enduring legacy continues to inspire countless people to begin their coding journeys.

programming languagescode examplesPerformance comparisonsoftware fundamentalsHello World
21CTO
Written by

21CTO

21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.