|
| 1 | + |
| 2 | +import asv |
| 3 | +import timeit |
| 4 | + |
| 5 | +from pydicom import dcmread |
| 6 | +from pydicom.data import get_testdata_file |
| 7 | +from pydicom.encaps import generate_pixel_data_frame |
| 8 | +from pydicom.pixel_data_handlers.rle_handler import ( |
| 9 | + get_pixeldata, _rle_decode_frame, _rle_encode_row, rle_encode_frame |
| 10 | +) |
| 11 | +from pydicom.pixel_data_handlers.util import reshape_pixel_array |
| 12 | +from pydicom.uid import RLELossless |
| 13 | + |
| 14 | +from ljdata import get_indexed_datasets |
| 15 | +from rle.utils import pixel_array, decode_frame |
| 16 | +from rle._rle import encode_row, encode_frame |
| 17 | + |
| 18 | +INDEX = get_indexed_datasets(RLELossless) |
| 19 | +# 8/8-bit, 1 sample/pixel, 1 frame |
| 20 | +EXPL_8_1_1F = get_testdata_file("OBXXXX1A.dcm") |
| 21 | +# 8/8-bit, 3 sample/pixel, 1 frame |
| 22 | +EXPL_8_3_1F = get_testdata_file("SC_rgb.dcm") |
| 23 | +# 16/16-bit, 1 sample/pixel, 1 frame |
| 24 | +EXPL_16_1_1F = get_testdata_file("MR_small.dcm") |
| 25 | +# 16/16-bit, 3 sample/pixel, 1 frame |
| 26 | +EXPL_16_3_1F = get_testdata_file("SC_rgb_16bit.dcm") |
| 27 | +# 32/32-bit, 1 sample/pixel, 1 frame |
| 28 | +EXPL_32_1_1F = get_testdata_file("rtdose_1frame.dcm") |
| 29 | +# 32/32-bit, 3 sample/pixel, 1 frame |
| 30 | +EXPL_32_3_1F = get_testdata_file("SC_rgb_32bit.dcm") |
| 31 | + |
| 32 | + |
| 33 | +class TimeEncodeRow: |
| 34 | + def setup(self): |
| 35 | + self.no_runs = 100000 |
| 36 | + ds = u8_1s_1f_rle |
| 37 | + arr = ds.pixel_array |
| 38 | + self.row_arr = arr[0, :].ravel() |
| 39 | + self.row = self.row_arr.tobytes() |
| 40 | + |
| 41 | + def time_rle(self): |
| 42 | + for _ in range(self.no_runs): |
| 43 | + encode_row(self.row) |
| 44 | + |
| 45 | + def time_default(self): |
| 46 | + for _ in range(self.no_runs): |
| 47 | + _rle_encode_row(self.row_arr) |
| 48 | + |
| 49 | + |
| 50 | +class TimePYDEncodeFrame: |
| 51 | + """Time tests for rle_handler.rle_encode_frame.""" |
| 52 | + def setup(self): |
| 53 | + ds = dcmread(EXPL_8_1_1F) |
| 54 | + self.arr8_1 = ds.pixel_array |
| 55 | + ds = dcmread(EXPL_8_3_1F) |
| 56 | + self.arr8_3 = ds.pixel_array |
| 57 | + ds = dcmread(EXPL_16_1_1F) |
| 58 | + self.arr16_1 = ds.pixel_array |
| 59 | + ds = dcmread(EXPL_16_3_1F) |
| 60 | + self.arr16_3 = ds.pixel_array |
| 61 | + ds = dcmread(EXPL_32_1_1F) |
| 62 | + self.arr32_1 = ds.pixel_array |
| 63 | + ds = dcmread(EXPL_32_3_1F) |
| 64 | + self.arr32_3 = ds.pixel_array |
| 65 | + |
| 66 | + self.no_runs = 1000 |
| 67 | + |
| 68 | + def time_08_1(self): |
| 69 | + """Time encoding 8 bit 1 sample/pixel.""" |
| 70 | + for ii in range(self.no_runs): |
| 71 | + rle_encode_frame(self.arr8_1) |
| 72 | + |
| 73 | + def time_08_3(self): |
| 74 | + """Time encoding 8 bit 3 sample/pixel.""" |
| 75 | + for ii in range(self.no_runs): |
| 76 | + rle_encode_frame(self.arr8_3) |
| 77 | + |
| 78 | + def time_16_1(self): |
| 79 | + """Time encoding 16 bit 1 sample/pixel.""" |
| 80 | + for ii in range(self.no_runs): |
| 81 | + rle_encode_frame(self.arr16_1) |
| 82 | + |
| 83 | + def time_16_3(self): |
| 84 | + """Time encoding 16 bit 3 sample/pixel.""" |
| 85 | + for ii in range(self.no_runs): |
| 86 | + rle_encode_frame(self.arr16_3) |
| 87 | + |
| 88 | + def time_32_1(self): |
| 89 | + """Time encoding 32 bit 1 sample/pixel.""" |
| 90 | + for ii in range(self.no_runs): |
| 91 | + rle_encode_frame(self.arr32_1) |
| 92 | + |
| 93 | + def time_32_3(self): |
| 94 | + """Time encoding 32 bit 3 sample/pixel.""" |
| 95 | + for ii in range(self.no_runs): |
| 96 | + rle_encode_frame(self.arr32_3) |
| 97 | + |
| 98 | + |
| 99 | +class TimeRLEEncodeFrame: |
| 100 | + def setup(self): |
| 101 | + ds = dcmread(EXPL_8_1_1F) |
| 102 | + self.ds8_1 = ( |
| 103 | + ds.PixelData, ds.Rows, ds.Columns, ds.SamplesPerPixel, ds.BitsAllocated, |
| 104 | + ) |
| 105 | + ds = dcmread(EXPL_8_3_1F) |
| 106 | + self.ds8_3 = ( |
| 107 | + ds.PixelData, ds.Rows, ds.Columns, ds.SamplesPerPixel, ds.BitsAllocated, |
| 108 | + ) |
| 109 | + ds = dcmread(EXPL_16_1_1F) |
| 110 | + self.ds16_1 = ( |
| 111 | + ds.PixelData, ds.Rows, ds.Columns, ds.SamplesPerPixel, ds.BitsAllocated, |
| 112 | + ) |
| 113 | + ds = dcmread(EXPL_16_3_1F) |
| 114 | + self.ds16_3 = ( |
| 115 | + ds.PixelData, ds.Rows, ds.Columns, ds.SamplesPerPixel, ds.BitsAllocated, |
| 116 | + ) |
| 117 | + ds = dcmread(EXPL_32_1_1F) |
| 118 | + self.ds32_1 = ( |
| 119 | + ds.PixelData, ds.Rows, ds.Columns, ds.SamplesPerPixel, ds.BitsAllocated, |
| 120 | + ) |
| 121 | + ds = dcmread(EXPL_32_3_1F) |
| 122 | + self.ds32_3 = ( |
| 123 | + ds.PixelData, ds.Rows, ds.Columns, ds.SamplesPerPixel, ds.BitsAllocated, |
| 124 | + ) |
| 125 | + |
| 126 | + self.no_runs = 1000 |
| 127 | + |
| 128 | + def time_08_1(self): |
| 129 | + """Time encoding 8 bit 1 sample/pixel.""" |
| 130 | + for ii in range(self.no_runs): |
| 131 | + encode_frame(*self.ds8_1, '<') |
| 132 | + |
| 133 | + def time_08_3(self): |
| 134 | + """Time encoding 8 bit 3 sample/pixel.""" |
| 135 | + for ii in range(self.no_runs): |
| 136 | + encode_frame(*self.ds8_3, '<') |
| 137 | + |
| 138 | + def time_16_1(self): |
| 139 | + """Time encoding 16 bit 1 sample/pixel.""" |
| 140 | + for ii in range(self.no_runs): |
| 141 | + encode_frame(*self.ds16_1, '<') |
| 142 | + |
| 143 | + def time_16_3(self): |
| 144 | + """Time encoding 16 bit 3 sample/pixel.""" |
| 145 | + for ii in range(self.no_runs): |
| 146 | + encode_frame(*self.ds16_3, '<') |
| 147 | + |
| 148 | + def time_32_1(self): |
| 149 | + """Time encoding 32 bit 1 sample/pixel.""" |
| 150 | + for ii in range(self.no_runs): |
| 151 | + encode_frame(*self.ds32_1, '<') |
| 152 | + |
| 153 | + def time_32_3(self): |
| 154 | + """Time encoding 32 bit 3 sample/pixel.""" |
| 155 | + for ii in range(self.no_runs): |
| 156 | + encode_frame(*self.ds32_3, '<') |
0 commit comments