From 74a0743045a2732456bc0b75d4101a019f5cbf3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B5=D0=BB=D0=B8=D0=BF=D0=B5=D0=BD=D0=BA=D0=BE=20?= =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD?= Date: Wed, 17 Oct 2018 08:13:47 +0000 Subject: [PATCH] git-svn-id: svn://db.shs.com.ru/pip@648 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5 --- main.cpp | 35 ++++++++++++++++++----------------- src_main/math/pievaluator.cpp | 9 +++++---- src_main/math/pievaluator.h | 34 +++++++++++++++------------------- 3 files changed, 38 insertions(+), 40 deletions(-) diff --git a/main.cpp b/main.cpp index 6324aedb..6c9b2925 100644 --- a/main.cpp +++ b/main.cpp @@ -42,28 +42,29 @@ public: }; int main() { PIEvaluator eval, eval2; - piCout << "start"; - - eval.setVariable("x", complexd(1, 2)); - PITimeMeasurer tm; - eval.check("e2eelg(10ex"); - double us = tm.elapsed_u(); piCout << "check" << us; - - tm.reset(); + eval.setVariable("t", complexd(1, 2)); + eval.check("(t*t*(t<8))+(72*(t>8)-8*(9-t)*(9-t)*(t>8)*(t<8.8))+(3*(t-8.8)*(t>8.8))"); PIByteArray ba = eval.save(); - us = tm.elapsed_u(); piCout << " save" << us; - piCout << ba.size(); + PITimeMeasurer tm; double us = 0.; tm.reset(); - eval2.load(ba); - us = tm.elapsed_u(); piCout << " load" << us; + PIEvaluator e1; + piForTimes(100) { + e1.setVariable("t", complexd(1, 2)); + e1.check("(t*t*(t<8))+(72*(t>8)-8*(9-t)*(9-t)*(t>8)*(t<8.8))+(3*(t-8.8)*(t>8.8))"); + complexd ret = e1.evaluate(); + } + us = tm.elapsed_u(); piCout << "check" << us / 100.; - //eval.setVariable("x", complexd(-2, 0)); - eval2.setVariable("x", complexd(-2, 0)); - - piCout << eval.expression() << "=" << eval.evaluate(); - piCout << eval2.expression() << "=" << eval2.evaluate(); + tm.reset(); + PIEvaluator e2; + piForTimes(100) { + e2.load(ba); + e2.setVariable("t", complexd(1, 2)); + complexd ret = e2.evaluate(); + } + us = tm.elapsed_u(); piCout << " save" << us / 100.; /*A a; CONNECTU(PICout::Notifier::object(), finished, &a, pcf); diff --git a/src_main/math/pievaluator.cpp b/src_main/math/pievaluator.cpp index e1754ca3..7e72bb02 100755 --- a/src_main/math/pievaluator.cpp +++ b/src_main/math/pievaluator.cpp @@ -710,7 +710,7 @@ PIString PIEvaluator::preprocess(const PIString & string) { lind = parse(currentString); if (instructions.size() == 0) { variables.push_back(PIEvaluatorTypes::Variable()); - instructions.push_back(PIEvaluatorTypes::Instruction(PIEvaluatorTypes::oNone, PIVector(1, lind), -variables.size_s())); + instructions.push_back(PIEvaluatorTypes::Instruction(PIEvaluatorTypes::oNone, PIVector(1, lind), -variables.size_s())); } kvars = &(content.variables); /* @@ -762,7 +762,7 @@ int PIEvaluator::parse(const PIString & string, int offset) { PIEvaluatorTypes::Function cfunc; PIEvaluatorTypes::Operation coper; PIString sbrackets, carg; - PIVector args, atmp; + PIVector args, atmp; PIVector opers; ///qDebug() << "to parse :" + string; @@ -1271,12 +1271,13 @@ complexd PIEvaluator::evaluate() { PIByteArray PIEvaluator::save() const { PIByteArray ret; - ret << content << elements << currentVariables << unknownVars << variables << instructions << currentString << lastError << out << correct; + ret << content << currentVariables << unknownVars << instructions << currentString << lastError << out << correct; return ret; } void PIEvaluator::load(PIByteArray ba) { if (ba.size() <= 4) return; - ba >> content >> elements >> currentVariables >> unknownVars >> variables >> instructions >> currentString >> lastError >> out >> correct; + ba >> content >> currentVariables >> unknownVars >> instructions >> currentString >> lastError >> out >> correct; + variables = currentVariables; } diff --git a/src_main/math/pievaluator.h b/src_main/math/pievaluator.h index ce4513fe..51b1f804 100755 --- a/src_main/math/pievaluator.h +++ b/src_main/math/pievaluator.h @@ -52,29 +52,29 @@ namespace PIEvaluatorTypes { struct PIP_EXPORT Instruction { Instruction() {out = -1; function = -1; operation = oNone;} - Instruction(Operation oper, PIVector opers, int out_ind, int func = -1) { + Instruction(Operation oper, PIVector opers, short out_ind, short func = -1) { operation = oper; operators = opers; out = out_ind; function = func;} Operation operation; - PIVector operators; - int out; - int function; + short out; + short function; + PIVector operators; }; struct PIP_EXPORT Element { Element() {num = 0; var_num = -1; type = etNumber;} - Element(eType new_type, int new_num, int new_var_num = -1) {set(new_type, new_num, new_var_num);} - void set(eType new_type, int new_num, int new_var_num = -1) {type = new_type; num = new_num; var_num = new_var_num;} + Element(eType new_type, short new_num, short new_var_num = -1) {set(new_type, new_num, new_var_num);} + void set(eType new_type, short new_num, short new_var_num = -1) {type = new_type; num = new_num; var_num = new_var_num;} eType type; - int num; - int var_num; + short num; + short var_num; }; struct PIP_EXPORT Function { Function() {arguments = 0; type = bfUnknown; handler = 0;} - Function(const PIString & name, int args, BaseFunctions ftype) {identifier = name; arguments = args; type = ftype; handler = 0;} - Function(const PIString & name, int args, FuncFunc h) {identifier = name; arguments = args; type = bfCustom; handler = h;} + Function(const PIString & name, short args, BaseFunctions ftype) {identifier = name; arguments = args; type = ftype; handler = 0;} + Function(const PIString & name, short args, FuncFunc h) {identifier = name; arguments = args; type = bfCustom; handler = h;} PIString identifier; BaseFunctions type; FuncFunc handler; - int arguments; + short arguments; }; struct PIP_EXPORT Variable { Variable() {value = 0.;} @@ -235,23 +235,19 @@ inline bool operator ==(PIEvaluatorTypes::Element e1, PIEvaluatorTypes::Element inline bool operator !=(PIEvaluatorTypes::Element e1, PIEvaluatorTypes::Element e2) {return (e1.type != e2.type || e1.num != e2.num);} inline PIByteArray & operator <<(PIByteArray & s, const PIEvaluatorTypes::Instruction & v) { - s << ((int)v.operation) << v.operators << v.out << v.function; + s << PIByteArray::RawData(&v, sizeof(v) - sizeof(v.operators)) << v.operators; return s; } inline PIByteArray & operator >>(PIByteArray & s, PIEvaluatorTypes::Instruction & v) { - int i(0); - s >> i >> v.operators >> v.out >> v.function; - v.operation = (PIEvaluatorTypes::Operation)i; + s >> PIByteArray::RawData(&v, sizeof(v) - sizeof(v.operators)) >> v.operators; return s; } inline PIByteArray & operator <<(PIByteArray & s, const PIEvaluatorTypes::Element & v) { - s << ((int)v.type) << v.num << v.var_num; + s << PIByteArray::RawData(&v, sizeof(v)); return s; } inline PIByteArray & operator >>(PIByteArray & s, PIEvaluatorTypes::Element & v) { - int i(0); - s >> i >> v.num >> v.var_num; - v.type = (PIEvaluatorTypes::eType)i; + s >> PIByteArray::RawData(&v, sizeof(v)); return s; } inline PIByteArray & operator <<(PIByteArray & s, const PIEvaluatorTypes::Variable & v) {