Skip to content

Commit 98528ad

Browse files
committed
added calculation in loop
1 parent 175f2ab commit 98528ad

9 files changed

+30
-12
lines changed

README.md

+22-12
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
1-
# Example result on Mac:
2-
3-
Function: 1 + 2 + 3 + .. + 100000000
4-
5-
* Node.js: 157ms
6-
* Swift: 238ms
7-
* C++: 240ms
8-
* C: 241ms
9-
* Java: 513ms
10-
* Python: 3624ms
11-
* Ruby: 5733ms
12-
* Perl: 9691ms
1+
# Example result on Mac
2+
3+
### Function:
4+
5+
long sum = 0;
6+
for (Integer n = max; n > 0; n--) {
7+
double foo = n / 17;
8+
sum = sum + n ;
9+
}
10+
11+
12+
### Times
13+
| Language | Time Elapsed|
14+
|----------|------------:|
15+
| Node.js | 157ms|
16+
| Swift | 238ms|
17+
| C++ | 240ms|
18+
| C | 241ms|
19+
| Java | 513ms|
20+
| Python | 3624ms|
21+
| Ruby | 5733ms|
22+
| Perl | 9691ms|

Test.java

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public static void main(String [] args)
2121
public static int forEachLoopMaxInteger(Integer max) {
2222
long sum = 0;
2323
for (Integer n = max; n > 0; n--) {
24+
double foo = n / 17;
2425
sum = sum + n ;
2526
}
2627
return max;

test.c

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ long timediff(clock_t t1, clock_t t2) {
1010
int forEachLoopMaxInteger(long max) {
1111
long sum = 0;
1212
for (long n = max; n > 0; n--) {
13+
double foo = n / 17;
1314
sum = sum + n ;
1415
}
1516
return max;

test.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class Calculations
1010
int forEachLoopMaxInteger(long max) {
1111
long sum = 0;
1212
for (long n = max; n > 0; n--) {
13+
double foo = n / 17;
1314
sum = sum + n ;
1415
}
1516
return max;

test.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
function test(max) {
22
var sum = 0
33
for (var n = max; n > 0; n--) {
4+
foo = n / 17;
45
sum = sum + n;
56
}
67

test.pl

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ sub forEachLoopMaxInteger {
77
my $sum = 0;
88

99
for( $n = $_[0]; $n > 0; $n = $n - 1 ) {
10+
$foo = $n / 17;
1011
$sum = $sum + n;
1112
}
1213
return $sum;

test.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
def forEachLoopMaxInteger(max):
55
sum = 0
66
for n in xrange(0, max):
7+
foo = n / 17
78
sum = sum + n
89

910
return sum

test.ruby

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ end
66
def forEachLoopMaxInteger(max)
77
sum = 0
88
(0..max).each do |i|
9+
foo = i / 17
910
sum = sum + i
1011
end
1112

test.swift

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Cocoa
77
func forEachLoopMaxInteger(max: Int64) -> Int64 {
88
var sum : Int64 = 0
99
for (var n = max; n > 0; n--) {
10+
let _ = n / 17
1011
sum = sum + n
1112
}
1213
return max;

0 commit comments

Comments
 (0)