Hello World Programs in Different Languages
This post will demonstrate running hello world programs in different languages and also providing return time statistics
C++
Code
1
2
3
4
5
6
7
8
| #include <iostream>
using namespace std;
int main()
{
std::cout << "Hello, World!" << std::endl;
return 0;
}
|
Compile:
1
| $ c++ hello_cpp.cpp -o hello_cpp
|
Run:
1
2
3
4
5
6
| $ time ./hello_cpp
Hello, World!
real 0m0.005s
user 0m0.001s
sys 0m0.001s
|
Golang:
Code
1
2
3
4
5
6
7
| package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}
|
Compile:
1
| $ go build hello_golang.go
|
Run:
1
2
3
4
5
6
| time ./hello_golang
Hello, World!
real 0m0.006s
user 0m0.001s
sys 0m0.003s
|
Python
Code:
1
2
| #!/usr/bin/env python
print("Hello, World!")
|
Make it executable:
1
| $ chmod +x ./hello_python.py
|
Run:
1
2
3
4
5
6
| $ time ./hello_python.py
Hello, World!
real 0m0.033s
user 0m0.015s
sys 0m0.010s
|
Ruby
Code:
1
2
| #!/usr/bin/env ruby
puts "Hello, World!"
|
Make it executable:
1
| $ chmod +x ./hello_ruby.rb
|
Run:
1
2
3
4
5
6
| $ time ./hello_ruby.rb
Hello, World!
real 0m0.136s
user 0m0.080s
sys 0m0.024s
|
Java
Code:
1
2
3
4
5
| public class hello_java {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
|
Compile:
1
| $ javac hello_java.java
|
Run:
1
2
3
4
5
6
| $ time java hello_java
Hello, World!
real 0m0.114s
user 0m0.086s
sys 0m0.023s
|
Resource: