Skip to content

Commit 6dab325

Browse files
committed
Unify time measuring units in all implementations
1 parent 732776a commit 6dab325

File tree

5 files changed

+13
-12
lines changed

5 files changed

+13
-12
lines changed

C#/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* February 8, 2013
88
*
99
* Syntax: queens [-test] [N]
10-
*
10+
*
1111
******************************************************************************/
1212

1313
using System;
@@ -42,7 +42,7 @@ static void Main(string[] args)
4242
time = DateTime.Now.Ticks - time;
4343

4444
if (testing)
45-
Console.WriteLine(chess.Steps + "\t" + chess.Discards + "\t" + time / 10000);
45+
Console.WriteLine(chess.Steps + "\t" + chess.Discards + "\t" + time / 10);
4646
else
4747
{
4848
Console.WriteLine(chess.ToString());

JS/queens.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@ if (isNaN(n) || n < 4) {
2727

2828
var chess = new libchess.Chess(n)
2929
var hrtime = process.hrtime()
30-
var time = hrtime[0] + hrtime[1] / 1e9
30+
var time = hrtime[0] *1e6 + hrtime[1] / 1e3
3131

3232
chess.solve()
3333

3434
hrtime = process.hrtime()
35-
time = parseInt((hrtime[0] + hrtime[1] / 1e9 - time) * 1000)
35+
time = parseInt((hrtime[0] *1e6 + hrtime[1] / 1e3 - time))
3636

3737
if (testing)
3838
console.log(String(chess.steps()) + "\t" + chess.discards() + "\t" + time)
3939
else {
4040
console.log(String(chess))
41-
console.log("Solved in " + chess.steps() + " steps. Time: " + time + " ms.")
41+
console.log("Solved in " + chess.steps() + " steps. Time: " + time / 1000 + " ms.")
4242
}

Java/queens/Main.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,16 @@ public static void main(String[] args) {
4242
}
4343

4444
chess = new Chess(n);
45-
time = System.currentTimeMillis();
45+
time = System.nanoTime();
4646
chess.solve();
47-
time = System.currentTimeMillis() - time;
47+
time = System.nanoTime() - time;
4848

4949
if (testing) {
50-
System.out.println(chess.getSteps() + "\t" + chess.getDiscards() + "\t" + time);
50+
System.out.println(chess.getSteps() + "\t" + chess.getDiscards() + "\t" + time / 1000);
5151
} else {
5252
System.out.println(chess);
5353
System.out.print("Solved in " + chess.getSteps() + " steps. ");
54-
System.out.println("Time: " + time + " ms.");
54+
System.out.println("Time: " + time / 1000000 + " ms.");
5555
}
5656
}
5757
}

PHP/queens.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,14 @@
3434
$chess = new Chess($n);
3535
$time = microtime(true);
3636
$chess->solve();
37-
$time = (int)((microtime(true) - $time) * 1000);
37+
$time = (int)((microtime(true) - $time));
3838
$steps = $chess->steps();
3939
$discards = $chess->discards();
4040

4141
if ($testing)
4242
echo "$steps\t$discards\t$time\n";
4343
else {
4444
echo $chess;
45+
$time /= 1000;
4546
echo "Solved in $steps steps. Time: $time ms.\n";
4647
}

Python/queens.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@
3737
chess = Chess(n)
3838
time = perf_counter()
3939
chess.solve()
40-
time = int((perf_counter() - time) * 1000)
40+
time = int((perf_counter() - time) * 1e6)
4141

4242
if testing:
4343
print(str(chess.steps()) + "\t" + str(chess.discards()) + "\t" + str(time));
4444
else:
4545
print(chess)
46-
print("Solved in", chess.steps(), "steps. Time:", time, "ms.")
46+
print("Solved in", chess.steps(), "steps. Time:", time / 1000, "ms.")

0 commit comments

Comments
 (0)