Skip to content

Instantly share code, notes, and snippets.

@MaymoonaAlBoloshi
Last active June 2, 2023 16:13
Show Gist options
  • Save MaymoonaAlBoloshi/cda8b001583542f15017d2200fb16730 to your computer and use it in GitHub Desktop.
Save MaymoonaAlBoloshi/cda8b001583542f15017d2200fb16730 to your computer and use it in GitHub Desktop.
python, js in node, go, rust

JS

console.time("counter");
for (let i = 0; i < 1000000000; i++) {}
console.timeEnd("counter");

counter: 933.401ms

Python

import time

start = time.time()

for i in range(1000000000):
    pass

end = time.time()
print(f"Time taken: {end - start} seconds")

Time taken: 26.445303201675415 seconds

Go

package main

import (
	"fmt"
	"time"
)

func main() {
	start := time.Now()

	for i := 0; i < 1000000000; i++ {}

	fmt.Printf("Time taken: %v seconds\n", time.Since(start).Seconds())
}

Time taken: 0.356702567 seconds

Rust

use std::time::Instant;

fn main() {
    let start = Instant::now();

    for _i in 0..1000000000 {}

    println!("Time taken: {:.2} seconds", start.elapsed().as_secs_f64());
}

Time taken: 6.72 seconds

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment