FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pythonnet/src/perf_tests/BaselineComparisonBenchmarkBase.cs at master · sdpython/pythonnet · GitHub
This repository was archived by the owner on Jul 22, 2023. It is now read-only.
sdpython
pythonnet
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
pythonnet
/
src
/
perf_tests
/
BaselineComparisonBenchmarkBase.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
69 lines (59 loc) · 2.64 KB
Breadcrumbs
pythonnet
/
src
/
perf_tests
/
BaselineComparisonBenchmarkBase.cs
Copy path
File metadata and controls
69 lines (59 loc) · 2.64 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using
System
;
using
System
.
Collections
.
Generic
;
using
System
.
Linq
;
using
System
.
Reflection
;
using
Python
.
Runtime
;
namespace
Python
.
PerformanceTests
{
public
class
BaselineComparisonBenchmarkBase
{
public
BaselineComparisonBenchmarkBase
(
)
{
Console
.
WriteLine
(
$
"CWD:
{
Environment
.
CurrentDirectory
}
"
)
;
Console
.
WriteLine
(
$
"Using Python.Runtime from
{
typeof
(
PythonEngine
)
.
Assembly
.
Location
}
{
typeof
(
PythonEngine
)
.
Assembly
.
GetName
(
)
}
"
)
;
try
{
PythonEngine
.
Initialize
(
)
;
Console
.
WriteLine
(
"Python Initialized"
)
;
if
(
PythonEngine
.
BeginAllowThreads
(
)
==
IntPtr
.
Zero
)
throw
new
PythonException
(
)
;
Console
.
WriteLine
(
"Threading enabled"
)
;
}
catch
(
Exception
e
)
{
Console
.
WriteLine
(
e
)
;
throw
;
}
}
static
BaselineComparisonBenchmarkBase
(
)
{
string
pythonRuntimeDll
=
Environment
.
GetEnvironmentVariable
(
BaselineComparisonConfig
.
EnvironmentVariableName
)
;
if
(
string
.
IsNullOrEmpty
(
pythonRuntimeDll
)
)
{
throw
new
ArgumentException
(
"Required environment variable is missing"
,
BaselineComparisonConfig
.
EnvironmentVariableName
)
;
}
Console
.
WriteLine
(
"Preloading "
+
pythonRuntimeDll
)
;
Assembly
.
LoadFrom
(
pythonRuntimeDll
)
;
foreach
(
var
assembly
in
AppDomain
.
CurrentDomain
.
GetAssemblies
(
)
)
{
if
(
assembly
.
FullName
.
StartsWith
(
"Python.Runtime"
)
)
Console
.
WriteLine
(
assembly
.
Location
)
;
foreach
(
var
dependency
in
assembly
.
GetReferencedAssemblies
(
)
)
if
(
dependency
.
FullName
.
Contains
(
"Python.Runtime"
)
)
{
Console
.
WriteLine
(
$
"
{
assembly
}
->
{
dependency
}
"
)
;
}
}
AppDomain
.
CurrentDomain
.
AssemblyResolve
+=
CurrentDomainOnAssemblyResolve
;
}
static
Assembly
CurrentDomainOnAssemblyResolve
(
object
sender
,
ResolveEventArgs
args
)
{
if
(
!
args
.
Name
.
StartsWith
(
"Python.Runtime"
)
)
return
null
;
var
preloaded
=
AppDomain
.
CurrentDomain
.
GetAssemblies
(
)
.
FirstOrDefault
(
a
=>
a
.
GetName
(
)
.
Name
==
"Python.Runtime"
)
;
if
(
preloaded
!=
null
)
return
preloaded
;
string
pythonRuntimeDll
=
Environment
.
GetEnvironmentVariable
(
BaselineComparisonConfig
.
EnvironmentVariableName
)
;
if
(
string
.
IsNullOrEmpty
(
pythonRuntimeDll
)
)
return
null
;
return
Assembly
.
LoadFrom
(
pythonRuntimeDll
)
;
}
}
}
Back
|
FazBrowse Home
|
New Git URL