summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClement David <clement.david@esi-group.com>2020-03-11 11:34:02 +0100
committerClement David <clement.david@esi-group.com>2020-03-11 11:38:01 +0100
commit99ff8d26999a8099d21327411748b6d43c71d1b7 (patch)
tree8a4fc279a51670f3b6561a10b78746b2f145ea3a
parent5c5f20c776e4d8dbc833fbcd3851e115f008938f (diff)
downloadscilab-99ff8d26999a8099d21327411748b6d43c71d1b7.zip
scilab-99ff8d26999a8099d21327411748b6d43c71d1b7.tar.gz
Bug #3188 fixed - `part()` was slower since 4.1.2
Change-Id: Ief42881ad2dcb49134abb1f9172603866790e5ee
-rw-r--r--scilab/CHANGES.md1
-rw-r--r--scilab/modules/string/sci_gateway/cpp/sci_part.cpp38
-rw-r--r--scilab/modules/string/tests/benchmarks/bench_part2_matrix.tst24
3 files changed, 46 insertions, 17 deletions
diff --git a/scilab/CHANGES.md b/scilab/CHANGES.md
index 64c2623..f8ac952 100644
--- a/scilab/CHANGES.md
+++ b/scilab/CHANGES.md
@@ -265,6 +265,7 @@ Bug Fixes
265--------- 265---------
266 266
267### Bugs fixed in 6.1.0: 267### Bugs fixed in 6.1.0:
268* [#3188](https://bugzilla.scilab.org/3188): `part()` was slower than in Scilab 4.1.2.
268* [#16342](https://bugzilla.scilab.org/16342): `strcat()` was much slower in Scilab 6.0.2. 269* [#16342](https://bugzilla.scilab.org/16342): `strcat()` was much slower in Scilab 6.0.2.
269 270
270 271
diff --git a/scilab/modules/string/sci_gateway/cpp/sci_part.cpp b/scilab/modules/string/sci_gateway/cpp/sci_part.cpp
index 5c6c028..936f808 100644
--- a/scilab/modules/string/sci_gateway/cpp/sci_part.cpp
+++ b/scilab/modules/string/sci_gateway/cpp/sci_part.cpp
@@ -19,24 +19,24 @@
19 c(i,j) is the Input_StringMatrixing "s[v(1)]...s[v(n)]" ( s=mp(i,j) ). 19 c(i,j) is the Input_StringMatrixing "s[v(1)]...s[v(n)]" ( s=mp(i,j) ).
20 */ 20 */
21/*------------------------------------------------------------------------*/ 21/*------------------------------------------------------------------------*/
22#include "string_gw.hxx" 22#include "double.hxx"
23#include "funcmanager.hxx" 23#include "funcmanager.hxx"
24#include "function.hxx" 24#include "function.hxx"
25#include "string.hxx"
26#include "double.hxx"
27#include "overload.hxx" 25#include "overload.hxx"
26#include "string.hxx"
27#include "string_gw.hxx"
28 28
29extern "C" 29extern "C"
30{ 30{
31#include <string.h>
32#include <stdio.h>
33#include "Scierror.h" 31#include "Scierror.h"
34#include "localization.h"
35#include "freeArrayOfString.h" 32#include "freeArrayOfString.h"
33#include "localization.h"
36#include "partfunction.h" 34#include "partfunction.h"
35#include <stdio.h>
36#include <string.h>
37} 37}
38/*--------------------------------------------------------------------------*/ 38/*--------------------------------------------------------------------------*/
39types::Function::ReturnValue sci_part(types::typed_list &in, int _iRetCount, types::typed_list &out) 39types::Function::ReturnValue sci_part(types::typed_list& in, int _iRetCount, types::typed_list& out)
40{ 40{
41 if (in.size() != 2) 41 if (in.size() != 2)
42 { 42 {
@@ -67,7 +67,7 @@ types::Function::ReturnValue sci_part(types::typed_list &in, int _iRetCount, typ
67 67
68 if (in[1]->isDouble() == false) 68 if (in[1]->isDouble() == false)
69 { 69 {
70 std::wstring wstFuncName = L"%" + in[1]->getShortTypeStr() + L"_part"; 70 std::wstring wstFuncName = L"%" + in[1]->getShortTypeStr() + L"_part";
71 return Overload::call(wstFuncName, in, _iRetCount, out); 71 return Overload::call(wstFuncName, in, _iRetCount, out);
72 } 72 }
73 73
@@ -81,7 +81,7 @@ types::Function::ReturnValue sci_part(types::typed_list &in, int _iRetCount, typ
81 81
82 size_t i_len = pD->getSize(); 82 size_t i_len = pD->getSize();
83 std::vector<int> index(i_len); 83 std::vector<int> index(i_len);
84 for (int i = 0 ; i < i_len; i++) 84 for (int i = 0; i < i_len; i++)
85 { 85 {
86 int idx = static_cast<int>(pD->get()[i]); 86 int idx = static_cast<int>(pD->get()[i]);
87 if (idx < 1) 87 if (idx < 1)
@@ -93,16 +93,22 @@ types::Function::ReturnValue sci_part(types::typed_list &in, int _iRetCount, typ
93 index[i] = idx; 93 index[i] = idx;
94 } 94 }
95 95
96 //wchar_t** pwstOut = partfunctionW(pS->get(), pS->getRows(), pS->getCols(), piIndex, pD->getSize());
97 types::String* pOut = new types::String(pS->getRows(), pS->getCols()); 96 types::String* pOut = new types::String(pS->getRows(), pS->getCols());
98 std::wstring string_in; 97 std::wstring string_in;
99 std::wstring string_out;
100 98
99 // allocate the output strings
100 std::wstring string_out(i_len, L' ');
101 for (int i = 0; i < pS->getSize(); ++i) 101 for (int i = 0; i < pS->getSize(); ++i)
102 { 102 {
103 string_in.assign(pS->get()[i]); 103 pOut->set(i, string_out.data());
104 size_t s_len = string_in.size(); 104 }
105 string_out.assign(i_len, L' '); 105
106 // part() algorithm
107 for (int i = 0; i < pS->getSize(); ++i)
108 {
109 wchar_t* wcs_in = pS->get()[i];
110 wchar_t* wcs_out = pOut->get()[i];
111 size_t s_len = wcslen(wcs_in);
106 112
107 for (int j = 0; j < i_len; ++j) 113 for (int j = 0; j < i_len; ++j)
108 { 114 {
@@ -111,10 +117,8 @@ types::Function::ReturnValue sci_part(types::typed_list &in, int _iRetCount, typ
111 continue; 117 continue;
112 } 118 }
113 119
114 string_out[j] = string_in[index[j] - 1]; 120 wcs_out[j] = wcs_in[index[j] - 1];
115 } 121 }
116
117 pOut->set(i, string_out.data());
118 } 122 }
119 123
120 out.push_back(pOut); 124 out.push_back(pOut);
diff --git a/scilab/modules/string/tests/benchmarks/bench_part2_matrix.tst b/scilab/modules/string/tests/benchmarks/bench_part2_matrix.tst
new file mode 100644
index 0000000..e90896a
--- /dev/null
+++ b/scilab/modules/string/tests/benchmarks/bench_part2_matrix.tst
@@ -0,0 +1,24 @@
1// =============================================================================
2// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3// Copyright (C) 2020 - ESI Group - Clement DAVID
4//
5// This file is distributed under the same license as the Scilab package.
6// =============================================================================
7
8//==============================================================================
9// Benchmark for part function
10//==============================================================================
11
12// <-- BENCH NB RUN : 400 -->
13// M*N are equals to bench_part2.tst NB RUN, bench timing should be the similar
14M=5;
15N=5;
16
17c = 1e5;
18str = strcat(string(int(rand(1, c) * 10)));
19idx = int(rand(1, c) * c + 1);
20str = str(ones(M, N));
21
22// <-- BENCH START -->
23part(str, idx);
24// <-- BENCH END -->