Skip to content

Instantly share code, notes, and snippets.

@reshadman
Created May 3, 2015 17:15
Show Gist options
  • Save reshadman/92ca923552f191478271 to your computer and use it in GitHub Desktop.
Save reshadman/92ca923552f191478271 to your computer and use it in GitHub Desktop.
Simple loop in programming languages -- for permance benchmarking of a WHILE LOOP --
#include <stdio.h>
void main(int argc, char *argv[]){
int i = 0;
int total = 500000000;
int chunked = 50000000;
while(total > i)
{
if(i % chunked == 0) printf("%d\n", i);
i++;
}
}
package main
import "fmt"
func main()
{
total := 500000000
chunk := 50000000
i := 0
for i < total {
if(i % chunk == 0)
{
fmt.Println(i)
}
i += 1
}
}
public class Loop {
public static void main(String[] args)
{
Integer total = 500000000;
Integer chunk = 50000000;
Integer i = 0;
while(i < total)
{
if(i % chunk == 0)
{
System.out.println(i);
}
i++;
}
}
}
var total = 500000000;
var chunk = 50000000;
var i = 0;
while(i < total)
{
if(i % chunk == 0) console.log(i);
i++;
}
<?php
$i = 0;
$total = 500000000;
$chunk = 50000000;
while ($i < $total)
{
if($i % $chunk == 0) echo "i : " . $i . "\n";
$i++;
}
?>
total = 500000000
chunk = 50000000
i = 0
while (i < total):
if(i % chunk == 0)
print('i: ',i)
i = i + 1
total = 500000000
chunk = 50000000
i = 0
while i < total
if i % chunk == 0
print "i: ", i, "\n"
end
i += 1
end
var i = 0;
val total: Int = 500000000;
val chunk: Int = 50000000;
while(i < total)
{
if(i % chunk == 0) println(i);
i += 1;
}
#!/bin/bash
total=500000000;
chunked=50000000;
i=0;
while [[ $i -lt $total ]]; do
if [[ $(($i % $chunked)) -eq 0 ]]; then
echo $i
fi
i=$((i+1))
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment