diff --git a/src/Fantomas.Cmd/Program.fs b/src/Fantomas.Cmd/Program.fs index 47d8a4fb0d..e41ac7ce4a 100644 --- a/src/Fantomas.Cmd/Program.fs +++ b/src/Fantomas.Cmd/Program.fs @@ -30,6 +30,7 @@ open Fantomas.FormatConfig let [] forceText = "Print the source unchanged if it cannot be parsed correctly." let [] recurseText = "Process the input folder recursively." let [] outputText = "Give a valid path for files/folders. Files should have .fs, .fsx, .fsi, .ml or .mli extension only." +let [] profileText = "Print performance profiling information." let [] fsiText = "Read F# source from stdin as F# signatures." let [] stdInText = "Read F# source from standard input." @@ -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 @@ -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 @@ -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 @@ -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); diff --git a/tests/output.txt b/tests/output.txt new file mode 100644 index 0000000000..0a686b0fbf --- /dev/null +++ b/tests/output.txt @@ -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. diff --git a/tests/profile.cmd b/tests/profile.cmd new file mode 100644 index 0000000000..20d2f3fd69 --- /dev/null +++ b/tests/profile.cmd @@ -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 \ No newline at end of file diff --git a/tests/stackexchange_output/rushhour.fs b/tests/stackexchange_output/rushhour.fs index a49fbc1161..cbdefbb4cb 100644 --- a/tests/stackexchange_output/rushhour.fs +++ b/tests/stackexchange_output/rushhour.fs @@ -193,4 +193,3 @@ let main argv = sw.Stop() Console.WriteLine(sw.Elapsed) 0 // return an integer exit code -