Created
May 3, 2015 17:15
-
-
Save reshadman/92ca923552f191478271 to your computer and use it in GitHub Desktop.
Simple loop in programming languages -- for permance benchmarking of a WHILE LOOP --
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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++; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
func main() | |
{ | |
total := 500000000 | |
chunk := 50000000 | |
i := 0 | |
for i < total { | |
if(i % chunk == 0) | |
{ | |
fmt.Println(i) | |
} | |
i += 1 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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++; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var total = 500000000; | |
var chunk = 50000000; | |
var i = 0; | |
while(i < total) | |
{ | |
if(i % chunk == 0) console.log(i); | |
i++; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$i = 0; | |
$total = 500000000; | |
$chunk = 50000000; | |
while ($i < $total) | |
{ | |
if($i % $chunk == 0) echo "i : " . $i . "\n"; | |
$i++; | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
total = 500000000 | |
chunk = 50000000 | |
i = 0 | |
while (i < total): | |
if(i % chunk == 0) | |
print('i: ',i) | |
i = i + 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
total = 500000000 | |
chunk = 50000000 | |
i = 0 | |
while i < total | |
if i % chunk == 0 | |
print "i: ", i, "\n" | |
end | |
i += 1 | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var i = 0; | |
val total: Int = 500000000; | |
val chunk: Int = 50000000; | |
while(i < total) | |
{ | |
if(i % chunk == 0) println(i); | |
i += 1; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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