File: ToMolMemoryTest.cs

package info (click to toggle)
rdkit 202503.1-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 220,160 kB
  • sloc: cpp: 399,240; python: 77,453; ansic: 25,517; java: 8,173; javascript: 4,005; sql: 2,389; yacc: 1,565; lex: 1,263; cs: 1,081; makefile: 580; xml: 229; fortran: 183; sh: 105
file content (91 lines) | stat: -rw-r--r-- 3,131 bytes parent folder | download | duplicates (2)
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using System;
using System.Diagnostics;
using GraphMolWrap;
using Xunit;

namespace RdkitTests
{
    public class ToMolMemoryTest
    {
        private static readonly long OneHundredMB = 1024 * 1024 * 100;
        private static readonly long TwoHundredMB = OneHundredMB * 2;

        private static void gc()
        {
            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();
        }


        [Fact]
        public void TestSmilesToMolMemoryUsage()
        {
            string smi =
                "CC(C)C[C@H](NC(=O)[C@H](CC(=O)O)NC(=O)[C@H](Cc1ccccc1)NC(=O)[C@H](CO)NC(=O)[C@@H]1CCCN1C(=O)[C@H](CCC(N)=O)NC(=O)[C@@H](N)CS)C(=O)N[C@@H](CCC(N)=O)C(=O)N[C@@H](CS)C(=O)O";

            var before = Process.GetCurrentProcess().VirtualMemorySize64;
            var privateBefore = Process.GetCurrentProcess().PrivateMemorySize64;
            long after;
            long privateAfter;
            for (int i = 0; i < 500; ++i)
            {
                RWMol mol = RDKFuncs.SmilesToMol(smi);
                RWMol mol2 = RWMol.MolFromSmiles(smi);
                if (i % 50 == 0)
                {
                    gc();
                    after = Process.GetCurrentProcess().VirtualMemorySize64;
                    Assert.True(after - before < TwoHundredMB);
                    privateAfter = Process.GetCurrentProcess().PrivateMemorySize64;
                    Assert.True(privateAfter - privateBefore < OneHundredMB);
                }
            }

            gc();
            after = Process.GetCurrentProcess().VirtualMemorySize64;
            Assert.True(after - before < TwoHundredMB);
            privateAfter = Process.GetCurrentProcess().PrivateMemorySize64;
            Assert.True(privateAfter - privateBefore < OneHundredMB);
        }

        [Fact]
        public void TestMolBlockToMolMemoryUsage()
        {
            var block = @"
     RDKit          2D

  6  6  0  0  0  0  0  0  0  0999 V2000
    1.5000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.7500   -1.2990    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -0.7500   -1.2990    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -1.5000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -0.7500    1.2990    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.7500    1.2990    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
  1  2  2  0
  2  3  1  0
  3  4  2  0
  4  5  1  0
  5  6  2  0
  6  1  1  0
M  END
";
            var before = Process.GetCurrentProcess().VirtualMemorySize64;
            long after;
            for (int i = 0; i < 500; ++i)
            {
                RWMol mol = RDKFuncs.MolBlockToMol(block);
                if (i % 50 == 0)
                {
                    gc();
                    after = Process.GetCurrentProcess().VirtualMemorySize64;
                    Assert.True(after - before < TwoHundredMB);
                }
            }

            gc();
            after = System.Diagnostics.Process.GetCurrentProcess().PeakVirtualMemorySize64;
            Assert.True(after - before < TwoHundredMB);
        }
    }
}