I am trying to count to 1000 with single core and dual core with esp32 but the output(run time) dose not make sense, the time which takes a single core should be doubled compared to dual core in theory right?
Here is the code
TaskHandle_t Task1;
TaskHandle_t Task2;
SemaphoreHandle_t baton;
int i = 0;
long l;
void setup() {
Serial.begin(115200);
pinMode(2, OUTPUT);
pinMode(4, OUTPUT);
baton = xSemaphoreCreateMutex();
l = millis();
xTaskCreatePinnedToCore(
Task1code, /* Function to implement the task */
"Task1", /* Name of the task */
10000, /* Stack size in words */
NULL, /* Task input parameter */
1, /* Priority of the task */
&Task1, /* Task handle. */
0); /* Core where the task should run */
//single core or dual core execution
// xTaskCreatePinnedToCore(
// Task2code, /* Function to implement the task */
// "Task2", /* Name of the task */
// 10000, /* Stack size in words */
// NULL, /* Task input parameter */
// 1, /* Priority of the task */
// &Task2, /* Task handle. */
// 1); /* Core where the task should run */
}
void Task1code( void * parameter) {
while (true) {
xSemaphoreTake(baton, portMAX_DELAY);
xSemaphoreGive(baton);
delay(1);// I don't understand in here without this command output result is worse
i++;
if (i == 1000) {
l = millis()-1;
Serial.print("Done ");
Serial.print(xPortGetCoreID());
Serial.print(" ");
Serial.println(l);
}if(i>1000){
vTaskDelete(Task1);
}
}
}
void Task2code( void * parameter) {
while (true) {
xSemaphoreTake(baton, portMAX_DELAY);
xSemaphoreGive(baton);
delay(1);// I don't understand in here without this command output result is worse
i++;
if (i == 1000) {
l = millis()-1;
Serial.print("Done ");
Serial.print(xPortGetCoreID());
Serial.print(" ");
Serial.println(l);
}if(i>1000){
vTaskDelete(Task2);
}
}
}
void loop() {
}
The output I get for runtime
Single core :- 1033 ms
Dual core :- 701 ms
Without delay(1);
command the result is even more obvious
Single core :- 39 ms
Dual core :- 40 ms
How can I make my algorithm show that single core takes twice time as dual core execution time I wan't both cores to work parallel not one after the other.