Skip to content

Commit

Permalink
Add profile flag for performance meassurement
Browse files Browse the repository at this point in the history
  • Loading branch information
dungpa committed Jan 31, 2014
1 parent c17d541 commit 8da3dca
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 4 deletions.
16 changes: 13 additions & 3 deletions src/Fantomas.Cmd/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ open Fantomas.FormatConfig
let [<Literal>] forceText = "Print the source unchanged if it cannot be parsed correctly."
let [<Literal>] recurseText = "Process the input folder recursively."
let [<Literal>] outputText = "Give a valid path for files/folders. Files should have .fs, .fsx, .fsi, .ml or .mli extension only."
let [<Literal>] profileText = "Print performance profiling information."

let [<Literal>] fsiText = "Read F# source from stdin as F# signatures."
let [<Literal>] stdInText = "Read F# source from standard input."
Expand Down Expand Up @@ -95,6 +96,7 @@ let processSourceFile inFile (tw : TextWriter) config =
let main args =
let recurse = ref false
let force = ref false
let profile = ref false

let outputPath = ref Notknown
let inputPath = ref Unspecified
Expand Down Expand Up @@ -152,7 +154,10 @@ let main args =
try
printfn "Processing %s" inFile
use buffer = new StreamWriter(outFile)
time <| fun () ->
if !profile then
File.ReadLines(inFile) |> Seq.length |> printfn "Line count: %i"
time (fun () -> processSourceFile inFile buffer config)
else
processSourceFile inFile buffer config
buffer.Flush()
printfn "%s has been written." outFile
Expand All @@ -175,10 +180,14 @@ let main args =
if !force then
stdout.Write(File.ReadAllText inFile)

let stringToFile s (outFile : string) config =
let stringToFile (s : string) (outFile : string) config =
try
use buffer = new StreamWriter(outFile)
time (fun () -> processSourceString !fsi s buffer config)
if !profile then
printfn "Line count: %i" (s.Length - s.Replace(Environment.NewLine, "").Length)
time (fun () -> processSourceString !fsi s buffer config)
else
processSourceString !fsi s buffer config
buffer.Flush()
printfn "%s has been written." outFile
with
Expand All @@ -202,6 +211,7 @@ let main args =
let options =
[| ArgInfo("--recurse", ArgType.Set recurse, recurseText);
ArgInfo("--force", ArgType.Set force, forceText);
ArgInfo("--profile", ArgType.Set profile, profileText);

ArgInfo("--fsi", ArgType.Set fsi, fsiText);
ArgInfo("--stdin", ArgType.Set stdIn, stdInText);
Expand Down
152 changes: 152 additions & 0 deletions tests/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
Fantomas.exe --profile --indent 2 ../../../../tests/languageshootout --out ../../../../tests/languageshootout_output

Processing ../../../../tests/languageshootout\binarytrees.fs
Line count: 48
Time taken: 00:00:03.5401550 s
../../../../tests/languageshootout_output\binarytrees.fs has been written.

Processing ../../../../tests/languageshootout\binarytrees2.fs
Line count: 54
Time taken: 00:00:00.1053550 s
../../../../tests/languageshootout_output\binarytrees2.fs has been written.

Processing ../../../../tests/languageshootout\fannkuch.fs
Line count: 166
Time taken: 00:00:00.1312644 s
../../../../tests/languageshootout_output\fannkuch.fs has been written.
Processing ../../../../tests/languageshootout\fannkuch5.fs
Line count: 75
Time taken: 00:00:00.0579070 s
../../../../tests/languageshootout_output\fannkuch5.fs has been written.

Processing ../../../../tests/languageshootout\fannkuchredux2.fs
Line count: 65
Time taken: 00:00:00.0524984 s
../../../../tests/languageshootout_output\fannkuchredux2.fs has been written.

Processing ../../../../tests/languageshootout\fannkuchredux3.fs
Line count: 100
Time taken: 00:00:00.1786221 s
../../../../tests/languageshootout_output\fannkuchredux3.fs has been written.

Processing ../../../../tests/languageshootout\fasta.fs
Line count: 85
Time taken: 00:00:00.1029806 s
../../../../tests/languageshootout_output\fasta.fs has been written.

Processing ../../../../tests/languageshootout\fastaredux2.fs
Line count: 83
Time taken: 00:00:00.0865599 s
../../../../tests/languageshootout_output\fastaredux2.fs has been written.

Processing ../../../../tests/languageshootout\knucleotide.fs
Line count: 57
Time taken: 00:00:00.0712816 s
../../../../tests/languageshootout_output\knucleotide.fs has been written.

Processing ../../../../tests/languageshootout\mandelbrot3.fs
Line count: 98
Time taken: 00:00:00.0601278 s
../../../../tests/languageshootout_output\mandelbrot3.fs has been written.

Processing ../../../../tests/languageshootout\nbody.fs
Line count: 118
Time taken: 00:00:00.0784012 s
../../../../tests/languageshootout_output\nbody.fs has been written.

Processing ../../../../tests/languageshootout\pidigits.fs
Line count: 54
Time taken: 00:00:00.0496092 s
../../../../tests/languageshootout_output\pidigits.fs has been written.

Processing ../../../../tests/languageshootout\pidigits2.fs
Line count: 47
Time taken: 00:00:00.0468120 s
../../../../tests/languageshootout_output\pidigits2.fs has been written.

Processing ../../../../tests/languageshootout\regexdna.fs
Line count: 59
Time taken: 00:00:00.0676048 s
../../../../tests/languageshootout_output\regexdna.fs has been written.

Processing ../../../../tests/languageshootout\regexdna2.fs
Line count: 40
Time taken: 00:00:00.0446979 s
../../../../tests/languageshootout_output\regexdna2.fs has been written.

Processing ../../../../tests/languageshootout\regexdna3.fs
Line count: 71
Time taken: 00:00:00.0816734 s
../../../../tests/languageshootout_output\regexdna3.fs has been written.

Processing ../../../../tests/languageshootout\spectralnorm2.fs
Line count: 99
Time taken: 00:00:00.0754203 s
../../../../tests/languageshootout_output\spectralnorm2.fs has been written.

Processing ../../../../tests/languageshootout\threadring2.fs
Line count: 67
Time taken: 00:00:00.0604009 s
../../../../tests/languageshootout_output\threadring2.fs has been written.

Processing ../../../../tests/languageshootout\threadring3.fs
Line count: 36
Time taken: 00:00:00.0390559 s
../../../../tests/languageshootout_output\threadring3.fs has been written.

Processing ../../../../tests/languageshootout\threadring4.fs
Line count: 36
Time taken: 00:00:00.0337082 s
../../../../tests/languageshootout_output\threadring4.fs has been written.

Fantomas.exe --profile --indent 2 ../../../../tests/stackexchange --out ../../../../tests/stackexchange_output

Processing ../../../../tests/stackexchange\array.fs
Line count: 39
Time taken: 00:00:03.3274396 s
../../../../tests/stackexchange_output\array.fs has been written.

Processing ../../../../tests/stackexchange\color.fs
Line count: 38
Time taken: 00:00:00.2743552 s
../../../../tests/stackexchange_output\color.fs has been written.

Processing ../../../../tests/stackexchange\comments.fs
Line count: 21
Time taken: 00:00:00.0985186 s
../../../../tests/stackexchange_output\comments.fs has been written.

Processing ../../../../tests/stackexchange\katas.fs
Line count: 89
Time taken: 00:00:00.1361566 s
../../../../tests/stackexchange_output\katas.fs has been written.

Processing ../../../../tests/stackexchange\mergesort.fs
Line count: 45
Time taken: 00:00:00.1130463 s
../../../../tests/stackexchange_output\mergesort.fs has been written.

Processing ../../../../tests/stackexchange\neuralnetwork.fs
Line count: 40
Time taken: 00:00:00.0945541 s
../../../../tests/stackexchange_output\neuralnetwork.fs has been written.

Processing ../../../../tests/stackexchange\performance.fs
Line count: 79
Time taken: 00:00:00.0736004 s
../../../../tests/stackexchange_output\performance.fs has been written.

Processing ../../../../tests/stackexchange\rushhour.fs
Line count: 179
Time taken: 00:00:00.2412114 s
../../../../tests/stackexchange_output\rushhour.fs has been written.

Processing ../../../../tests/stackexchange\telnet.fs
Line count: 30
Time taken: 00:00:00.0396177 s
../../../../tests/stackexchange_output\telnet.fs has been written.

Processing ../../../../tests/stackexchange\typedesign.fs
Line count: 32
Time taken: 00:00:00.0379667 s
../../../../tests/stackexchange_output\typedesign.fs has been written.
4 changes: 4 additions & 0 deletions tests/profile.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pushd ..\src\Fantomas.Cmd\bin\Release
Fantomas.exe --profile --indent 2 ../../../../tests/languageshootout --out ../../../../tests/languageshootout_output
Fantomas.exe --profile --indent 2 ../../../../tests/stackexchange --out ../../../../tests/stackexchange_output
popd
1 change: 0 additions & 1 deletion tests/stackexchange_output/rushhour.fs
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,3 @@ let main argv =
sw.Stop()
Console.WriteLine(sw.Elapsed)
0 // return an integer exit code

0 comments on commit 8da3dca

Please sign in to comment.