Errores, fallos, preguntas - página 2315

 
fxsaber:

¿Por qué by_ref es más lento que by_val?

¿De dónde se desprende?

Si el código es el mismo

//Test.mqh
        int by_ref(string& var) { return int(var) % 100; }
        int by_val(string  var) { return int(var) % 100; }
//Test.mq5
#include "Test.mqh"
#define  ITERATIONS 1000000
#define  MACRO( X ) \
        { \
                ulong time = GetMicrosecondCount(); \
                for(int i=0; i<ITERATIONS; i++) \
                { \
                        string r = string( rand ); \
                        sum_##X += by_##X(r); \
                } \
                time_##X = GetMicrosecondCount() - time; \
        }
void OnStart()
{
        for ( int i = 0; i < 10; i++ )
                OnStart2( rand());
}
void OnStart2( int rand )
{
        long time_ref, sum_ref = 0;
        long time_val, sum_val = 0;
        MACRO( ref )
        MACRO( val )
        printf( "%+10.3f:%d", (time_ref-time_val)/1000.0, sum_ref-sum_val );
}

también lo hace el resultado (diferencia de tiempo de ejecución):

+12.221:0
+5.099:0
+0.149:0
-13.729:0
+14.531:0
-27.429:0
+26.405:0
-0.839:0
+5.400:0
-4.882:0

alternativo (+\-) dentro de límites insignificantes

 
A100:

¿De dónde viene?

#define  ITERATIONS 1000000

void OnStart()
{
   string Str = "1";
   
   for (int i = 0; i < 10; i++)
     Str += Str;
   
   for (int j = 0; j < 5; j++)
   {
     {
        ulong time = GetMicrosecondCount();
        ulong sum = 0;
        for(int i=0; i<ITERATIONS; i++){
           string r = string(rand()) + Str;
           sum += by_ref(r);
        }
        time = GetMicrosecondCount() - time;
        printf("%s took %.3f milliseconds: sum=%dll", "by_ref", time/1000.0, sum);
     }{
        ulong time = GetMicrosecondCount();
        ulong sum = 0;
        for(int i=0; i<ITERATIONS; i++)
           sum += by_val(string(rand()) + Str);
        time = GetMicrosecondCount() - time;
        printf("%s took %.3f milliseconds: sum=%dll", "by_val", time/1000.0, sum);
     }
     
     Print("");
   }
}
//+------------------------------------------------------------------+

int by_ref(string &var){ return int(var) % 100; }
int by_val(string  var){ return int(var) % 100; }


by_ref took 15119.806 milliseconds: sum=-1000000 ll
by_val took 13872.479 milliseconds: sum=-1000000 ll

by_ref took 14433.781 milliseconds: sum=-1000000 ll
by_val took 13817.533 milliseconds: sum=-1000000 ll

by_ref took 13889.424 milliseconds: sum=-1000000 ll
by_val took 14135.603 milliseconds: sum=-1000000 ll

by_ref took 16047.643 milliseconds: sum=-1000000 ll
by_val took 14494.432 milliseconds: sum=-1000000 ll

by_ref took 15542.276 milliseconds: sum=-1000000 ll
by_val took 13843.121 milliseconds: sum=-1000000 ll
 
Nikolai Semko:

Quise poner una nota en la KB y no funcionó. Y a juzgar por el hecho de que las últimas publicaciones no tienen ninguna calificación, parece que no soy el único con este problema.

Sí, no está funcionando.

 
fxsaber:
Mis bucles ref y val tienen el mismo código (la comparación es más o menos correcta), pero el tuyo es diferente
 
A100:
En mis bucles ref y val tienen el mismo código (la comparación es más o menos correcta), mientras que el tuyo es diferente

Sí, diferente. Pero la pregunta sigue siendo válida. ¿Por qué val-variant es notablemente más rápido que ref?

 
fxsaber:

Sí, diferente. Pero la pregunta sigue siendo válida. ¿Por qué la variante val es notablemente más rápida que la ref?

Tal vez la variante ref esté menos optimizada por el compilador, quién sabe.

En mi opinión, ambas variantes deberían compilar casi el mismo código o incluso completamente el mismo código, pero el compilador maneja las cosas de manera diferente

 
TheXpert:

Tal vez la variante ref esté peor optimizada por el compilador, quién sabe.

Me parece que ambos deberían compilar aproximadamente el mismo código o incluso exactamente el mismo, pero el compilador piensa de forma diferente

En realidad, la pregunta iba dirigida a los promotores, para que haya una base de discrepancias en los motivos de las mismas.

Normalmente intento pasar todo por referencia para agilizar. Y esto estaba justificado en algunas construcciones. Pero ahora me parece.

 
Alexey Kozitsyn:

+1. Algo parece estar roto. Bild 1881 x64. Ganar 10. Al arrancar carga la CPU en un 20+% (i5 8600k) y la RAM en 650-700mb (no aumenta).

El administrador de tareas muestra el estado "No responde".

Y el otro terminal 1881 (no el de Apertura) funciona bien.

Añadido:

Al final, sí que ha arrancado. Sin embargo, tardó muchísimo en arrancar, lo cual no es normal. Luego cerré el terminal y lo volví a abrir. Se abrió al instante. Al parecer, hubo algún problema con la carga de datos.

Solucionado al reinstalar el terminal. Accidentalmente saqué la carpeta con todos los ajustes y gráficos) volví a dibujar todo, pero ahora funciona como un reloj.
 
reztor:
La solución fue reinstalar el terminal. También borré accidentalmente la carpeta con todas las configuraciones y gráficos) dibujé todo de nuevo, pero ahora funciona como un reloj.

Esto no era necesario. Podría haber eliminado simplemente el archivo news.dat.

 
TheXpert:

Tal vez la variante ref esté peor optimizada por el compilador, ¿quién sabe?

En mi opinión, ambas opciones deberían compilar aproximadamente el mismo código o incluso completamente el mismo código, pero el compilador cuenta de manera diferente

¿Cuál es la relación entre el código final y su tiempo de ejecución?

Por ejemplo, cambiemos. .. para que los bucles sean absolutamente idénticos

#define  ITERATIONS 1000000
void OnStart()
{
   string Str = "1";
   for (int i = 0; i < 10; i++)
     Str += Str;
   for (int j = 0; j < 5; j++)
   {
     {
        ulong time = GetMicrosecondCount();
        ulong sum = 0;
        for(int i=0; i<ITERATIONS; i++)
           sum += by_ref(string(rand()) + Str);
        time = GetMicrosecondCount() - time;
        printf("%s took %.3f milliseconds: sum=%dll", "by_ref", time/1000.0, sum);
     }
     {
        ulong time = GetMicrosecondCount();
        ulong sum = 0;
        for(int i=0; i<ITERATIONS; i++)
           sum += by_val(string(rand()) + Str);
        time = GetMicrosecondCount() - time;
        printf("%s took %.3f milliseconds: sum=%dll", "by_val", time/1000.0, sum);
     }    
     Print("");
   }
}
int by_ref(string var){ return int(var) % 100; }
int by_val(string var){ return int(var) % 100; }

El resultado..:

by_ref tardó 18354,547 milisegundos: sum=1865600ll
by_val ha tardado 18318,319 milisegundos: sum=1861628ll

by_ref tardó 18416.747 milisegundos: sum=1904488ll
by_val tardó 18221,978 milisegundos: sum=1907860ll

by_ref tardó 18301,009 milisegundos: sum=1757988ll
by_val ha tardado 18545,258 milisegundos: sum=1949720ll

by_ref tardó 18373,648 milisegundos: sum=1867160ll
by_val tardó 17972,432 milisegundos: sum=1760308ll

by_ref tardó 19426,076 milisegundos: sum=1795564ll
by_val tardó 19177,485 milisegundos: sum=1826360ll

es más o menos lo mismo... ¿O crees que el compilador ha creado un código diferente en los mismos bucles?

Permítanme recordarles que había algo así

by_ref tardó 13889.424 milisegundos: sum=-1000000ll
by_val tardó 14135.603 milisegundos: sum=-1000000ll

y un código diferente... y hay más o menos la misma diferencia de tiempo, pero el código y las funciones en sí son exactamente las mismas

Razón de la queja: