diff --git a/TensorFlow.NET.sln b/TensorFlow.NET.sln index 874f8082..19a66b80 100644 --- a/TensorFlow.NET.sln +++ b/TensorFlow.NET.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.29025.244 +# Visual Studio 15 +VisualStudioVersion = 15.0.28307.645 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TensorFlowNET.UnitTest", "test\TensorFlowNET.UnitTest\TensorFlowNET.UnitTest.csproj", "{029A8CF1-CF95-4DCB-98AA-9D3D96A83B3E}" EndProject @@ -17,6 +17,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Keras.UnitTest", "test\Kera EndProject Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "TensorFlowNET.Examples.FSharp", "test\TensorFlowNET.Examples.FSharp\TensorFlowNET.Examples.FSharp.fsproj", "{62BC3801-F0D3-44A9-A0AC-712F40C8F961}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TensorFlowNet.Benchmark", "src\TensorFlowNet.Benchmarks\TensorFlowNet.Benchmark.csproj", "{68861442-971A-4196-876E-C9330F0B3C54}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -51,6 +53,10 @@ Global {62BC3801-F0D3-44A9-A0AC-712F40C8F961}.Debug|Any CPU.Build.0 = Debug|Any CPU {62BC3801-F0D3-44A9-A0AC-712F40C8F961}.Release|Any CPU.ActiveCfg = Release|Any CPU {62BC3801-F0D3-44A9-A0AC-712F40C8F961}.Release|Any CPU.Build.0 = Release|Any CPU + {68861442-971A-4196-876E-C9330F0B3C54}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {68861442-971A-4196-876E-C9330F0B3C54}.Debug|Any CPU.Build.0 = Debug|Any CPU + {68861442-971A-4196-876E-C9330F0B3C54}.Release|Any CPU.ActiveCfg = Release|Any CPU + {68861442-971A-4196-876E-C9330F0B3C54}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/TensorFlowNet.Benchmarks/Program.cs b/src/TensorFlowNet.Benchmarks/Program.cs new file mode 100644 index 00000000..4ba08cf1 --- /dev/null +++ b/src/TensorFlowNet.Benchmarks/Program.cs @@ -0,0 +1,40 @@ +using System; +using System.Reflection; +using BenchmarkDotNet.Configs; +using BenchmarkDotNet.Running; + +namespace TensorFlowNet.Benchmark +{ + class Program + { + /// + /// dotnet NumSharp.Benchmark.dll (Benchmark Class Name) + /// dotnet NumSharp.Benchmark.dll nparange + /// + /// + static void Main(string[] args) + { +#if DEBUG + IConfig config = new DebugInProcessConfig(); +#else + IConfig config = null; +#endif + + if (args?.Length > 0) + { + for (int i = 0; i < args.Length; i++) + { + string name = $"TensorFlowNet.Benchmark.{args[i]}"; + var type = Type.GetType(name); + BenchmarkRunner.Run(type, config); + } + } + else + { + BenchmarkSwitcher.FromAssembly(Assembly.GetExecutingAssembly()).Run(args, config); + } + + Console.ReadLine(); + } + } +} diff --git a/src/TensorFlowNet.Benchmarks/TensorCreation.cs b/src/TensorFlowNet.Benchmarks/TensorCreation.cs new file mode 100644 index 00000000..1ac849f3 --- /dev/null +++ b/src/TensorFlowNet.Benchmarks/TensorCreation.cs @@ -0,0 +1,55 @@ +using System; +using System.Linq; +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Engines; +using NumSharp; +using Tensorflow; + +namespace TensorFlowNet.Benchmark +{ + [SimpleJob(launchCount: 1, warmupCount: 10, targetCount: 30)] + [MinColumn, MaxColumn, MeanColumn, MedianColumn] + public class TensorCreation + { + private double[] data; + + [GlobalSetup] + public void Setup() + { + data = new double[1000]; + } + + [Benchmark] + public void TensorFromArray() + { + var g=new Graph(); + for (int i = 0; i < 100; i++) + { + var tensor = new Tensor(data); + } + } + + + [Benchmark] + public void TensorFromNDArray() + { + var g = new Graph(); + for (int i = 0; i < 100; i++) + { + var tensor = new Tensor(new NDArray(data)); + } + } + + //[Benchmark] + //public void Constant() + //{ + // for (int i = 0; i < 100; i++) + // { + // //var tensor = new Tensor(new NDArray(data)); + // var c = tf.constant(42.0); + // } + //} + + } +} + diff --git a/src/TensorFlowNet.Benchmarks/TensorFlowNet.Benchmark.csproj b/src/TensorFlowNet.Benchmarks/TensorFlowNet.Benchmark.csproj new file mode 100644 index 00000000..10f6e0a0 --- /dev/null +++ b/src/TensorFlowNet.Benchmarks/TensorFlowNet.Benchmark.csproj @@ -0,0 +1,22 @@ + + + + Exe + netcoreapp2.2 + + + + + + + + + + + + + PreserveNewest + + + + diff --git a/src/TensorFlowNet.Benchmarks/tensorflow.dll b/src/TensorFlowNet.Benchmarks/tensorflow.dll new file mode 100644 index 00000000..f98eb380 Binary files /dev/null and b/src/TensorFlowNet.Benchmarks/tensorflow.dll differ