Skip to content

Commit

Permalink
Merge pull request #4 from vikman90/fix-timing
Browse files Browse the repository at this point in the history
Wrong time measure in some implementations
  • Loading branch information
vikman90 committed Feb 23, 2024
2 parents ccd1142 + be99c13 commit f5d5cbd
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 14 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ on:
branches: [ "master" ]

env:
STEP: 16
STOP: 256
STEP: 64
STOP: 512
TIMEOUT: 1
ATTEMPTS: 3

Expand Down
4 changes: 2 additions & 2 deletions C#/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* February 8, 2013
*
* Syntax: queens [-test] [N]
*
*
******************************************************************************/

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

if (testing)
Console.WriteLine(chess.Steps + "\t" + chess.Discards + "\t" + time / 10000);
Console.WriteLine(chess.Steps + "\t" + chess.Discards + "\t" + time / 10);
else
{
Console.WriteLine(chess.ToString());
Expand Down
6 changes: 3 additions & 3 deletions JS/queens.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ if (isNaN(n) || n < 4) {

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

chess.solve()

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

if (testing)
console.log(String(chess.steps()) + "\t" + chess.discards() + "\t" + time)
else {
console.log(String(chess))
console.log("Solved in " + chess.steps() + " steps. Time: " + time + " ms.")
console.log("Solved in " + chess.steps() + " steps. Time: " + time / 1000 + " ms.")
}
8 changes: 4 additions & 4 deletions Java/queens/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ public static void main(String[] args) {
}

chess = new Chess(n);
time = System.currentTimeMillis();
time = System.nanoTime();
chess.solve();
time = System.currentTimeMillis() - time;
time = System.nanoTime() - time;

if (testing) {
System.out.println(chess.getSteps() + "\t" + chess.getDiscards() + "\t" + time);
System.out.println(chess.getSteps() + "\t" + chess.getDiscards() + "\t" + time / 1000);
} else {
System.out.println(chess);
System.out.print("Solved in " + chess.getSteps() + " steps. ");
System.out.println("Time: " + time + " ms.");
System.out.println("Time: " + time / 1000000 + " ms.");
}
}
}
3 changes: 2 additions & 1 deletion PHP/queens.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@
$chess = new Chess($n);
$time = microtime(true);
$chess->solve();
$time = (int)((microtime(true) - $time) * 1000);
$time = (int)((microtime(true) - $time) * 1e6);
$steps = $chess->steps();
$discards = $chess->discards();

if ($testing)
echo "$steps\t$discards\t$time\n";
else {
echo $chess;
$time /= 1000;
echo "Solved in $steps steps. Time: $time ms.\n";
}
4 changes: 2 additions & 2 deletions Python/queens.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
chess = Chess(n)
time = perf_counter()
chess.solve()
time = int((perf_counter() - time) * 1000)
time = int((perf_counter() - time) * 1e6)

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

0 comments on commit f5d5cbd

Please sign in to comment.