How can I calculate time of my main code?
I have a code which is included some functions. for every functions I use CPUTime. but in main model how can I calculate time. Please help me.
for example
using CPUTime
function Sminf2(ZB,ZT)
model=CreateModel();
WES=model[1];f1=model[2];f2=model[3];
rf1=model[4];rf2=model[5];lf1=model[6];
lf2=model[7];
x=WES[:x];
y=WES[:y];
JuMP.setRHS(rf1,ZB[1]);
JuMP.setRHS(lf1,ZT[1]);
JuMP.setRHS(rf2,ZT[2]);
JuMP.setRHS(lf2,ZB[2]);
@objective(WES,Min,f2);
status=solve(WES)
return getvalue(x)
end
@time @CPUtime Sminf2(ZB,ZT)
-----------------------------------------------------------------
but in this main code how can I calculate the time?
using JuMP,CPLEX,CPUTime
include("WEIGHT.juliarc (2).jl");
include("CreateModel.juliarc.jl");
include("Sminf2.juliarc.jl");
include("Sminf1.juliarc.jl");
pq=;
model=CreateModel();
WES=model[1];f1=model[2];f2=model[3];
rf1=model[4];rf2=model[5];lf1=model[6];
lf2=model[7];ofv1=model[8];ofv2=model[9];
x=WES[:x];
y=WES[:y];
for i=1:5
W=WEIGHT(Zb,Zt);
pq=[pq;W[1]];
end
println("PQ=",pq)
------------------------------------------------------------------------------
julia julia-jump
add a comment |
I have a code which is included some functions. for every functions I use CPUTime. but in main model how can I calculate time. Please help me.
for example
using CPUTime
function Sminf2(ZB,ZT)
model=CreateModel();
WES=model[1];f1=model[2];f2=model[3];
rf1=model[4];rf2=model[5];lf1=model[6];
lf2=model[7];
x=WES[:x];
y=WES[:y];
JuMP.setRHS(rf1,ZB[1]);
JuMP.setRHS(lf1,ZT[1]);
JuMP.setRHS(rf2,ZT[2]);
JuMP.setRHS(lf2,ZB[2]);
@objective(WES,Min,f2);
status=solve(WES)
return getvalue(x)
end
@time @CPUtime Sminf2(ZB,ZT)
-----------------------------------------------------------------
but in this main code how can I calculate the time?
using JuMP,CPLEX,CPUTime
include("WEIGHT.juliarc (2).jl");
include("CreateModel.juliarc.jl");
include("Sminf2.juliarc.jl");
include("Sminf1.juliarc.jl");
pq=;
model=CreateModel();
WES=model[1];f1=model[2];f2=model[3];
rf1=model[4];rf2=model[5];lf1=model[6];
lf2=model[7];ofv1=model[8];ofv2=model[9];
x=WES[:x];
y=WES[:y];
for i=1:5
W=WEIGHT(Zb,Zt);
pq=[pq;W[1]];
end
println("PQ=",pq)
------------------------------------------------------------------------------
julia julia-jump
add a comment |
I have a code which is included some functions. for every functions I use CPUTime. but in main model how can I calculate time. Please help me.
for example
using CPUTime
function Sminf2(ZB,ZT)
model=CreateModel();
WES=model[1];f1=model[2];f2=model[3];
rf1=model[4];rf2=model[5];lf1=model[6];
lf2=model[7];
x=WES[:x];
y=WES[:y];
JuMP.setRHS(rf1,ZB[1]);
JuMP.setRHS(lf1,ZT[1]);
JuMP.setRHS(rf2,ZT[2]);
JuMP.setRHS(lf2,ZB[2]);
@objective(WES,Min,f2);
status=solve(WES)
return getvalue(x)
end
@time @CPUtime Sminf2(ZB,ZT)
-----------------------------------------------------------------
but in this main code how can I calculate the time?
using JuMP,CPLEX,CPUTime
include("WEIGHT.juliarc (2).jl");
include("CreateModel.juliarc.jl");
include("Sminf2.juliarc.jl");
include("Sminf1.juliarc.jl");
pq=;
model=CreateModel();
WES=model[1];f1=model[2];f2=model[3];
rf1=model[4];rf2=model[5];lf1=model[6];
lf2=model[7];ofv1=model[8];ofv2=model[9];
x=WES[:x];
y=WES[:y];
for i=1:5
W=WEIGHT(Zb,Zt);
pq=[pq;W[1]];
end
println("PQ=",pq)
------------------------------------------------------------------------------
julia julia-jump
I have a code which is included some functions. for every functions I use CPUTime. but in main model how can I calculate time. Please help me.
for example
using CPUTime
function Sminf2(ZB,ZT)
model=CreateModel();
WES=model[1];f1=model[2];f2=model[3];
rf1=model[4];rf2=model[5];lf1=model[6];
lf2=model[7];
x=WES[:x];
y=WES[:y];
JuMP.setRHS(rf1,ZB[1]);
JuMP.setRHS(lf1,ZT[1]);
JuMP.setRHS(rf2,ZT[2]);
JuMP.setRHS(lf2,ZB[2]);
@objective(WES,Min,f2);
status=solve(WES)
return getvalue(x)
end
@time @CPUtime Sminf2(ZB,ZT)
-----------------------------------------------------------------
but in this main code how can I calculate the time?
using JuMP,CPLEX,CPUTime
include("WEIGHT.juliarc (2).jl");
include("CreateModel.juliarc.jl");
include("Sminf2.juliarc.jl");
include("Sminf1.juliarc.jl");
pq=;
model=CreateModel();
WES=model[1];f1=model[2];f2=model[3];
rf1=model[4];rf2=model[5];lf1=model[6];
lf2=model[7];ofv1=model[8];ofv2=model[9];
x=WES[:x];
y=WES[:y];
for i=1:5
W=WEIGHT(Zb,Zt);
pq=[pq;W[1]];
end
println("PQ=",pq)
------------------------------------------------------------------------------
julia julia-jump
julia julia-jump
asked Jan 2 at 5:35
Somayeh EsmaeiliSomayeh Esmaeili
628
628
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Generally, it is recommended to use BenchmarkTools.jl for benchmarking a piece of code.
Paralleling the @time
macro in Base
Julia, BenchmarkTools
exports the usually superior @btime
macro, which, among other things, avoids measuring compilation time and performs a more precise statistical analysis. (see the package's documentation for details)
You can use it just as you use the @time
macro, e.g. @btime rand(2,2)
To benchmark a block of code, such as your "main code", you could (and should) put that piece of code into a function or a begin ... end
block. For example,
@btime begin
# my code goes here
end
Note that, independent of benchmarking, it is anyways recommended to put performance critical code into functions, as is explained in the Performance Tips in Julia's documentation.
Having introduced @btime
, of course, if the runtime of your code dominates over compilation time, as should probably be the case when benchmarking the whole code ("main code"), it's often nonetheless fine to use @time
. It should be instructive to read this recent discourse thread where parts of how to use @time
correctly have been discussed.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54001682%2fhow-can-i-calculate-time-of-my-main-code%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Generally, it is recommended to use BenchmarkTools.jl for benchmarking a piece of code.
Paralleling the @time
macro in Base
Julia, BenchmarkTools
exports the usually superior @btime
macro, which, among other things, avoids measuring compilation time and performs a more precise statistical analysis. (see the package's documentation for details)
You can use it just as you use the @time
macro, e.g. @btime rand(2,2)
To benchmark a block of code, such as your "main code", you could (and should) put that piece of code into a function or a begin ... end
block. For example,
@btime begin
# my code goes here
end
Note that, independent of benchmarking, it is anyways recommended to put performance critical code into functions, as is explained in the Performance Tips in Julia's documentation.
Having introduced @btime
, of course, if the runtime of your code dominates over compilation time, as should probably be the case when benchmarking the whole code ("main code"), it's often nonetheless fine to use @time
. It should be instructive to read this recent discourse thread where parts of how to use @time
correctly have been discussed.
add a comment |
Generally, it is recommended to use BenchmarkTools.jl for benchmarking a piece of code.
Paralleling the @time
macro in Base
Julia, BenchmarkTools
exports the usually superior @btime
macro, which, among other things, avoids measuring compilation time and performs a more precise statistical analysis. (see the package's documentation for details)
You can use it just as you use the @time
macro, e.g. @btime rand(2,2)
To benchmark a block of code, such as your "main code", you could (and should) put that piece of code into a function or a begin ... end
block. For example,
@btime begin
# my code goes here
end
Note that, independent of benchmarking, it is anyways recommended to put performance critical code into functions, as is explained in the Performance Tips in Julia's documentation.
Having introduced @btime
, of course, if the runtime of your code dominates over compilation time, as should probably be the case when benchmarking the whole code ("main code"), it's often nonetheless fine to use @time
. It should be instructive to read this recent discourse thread where parts of how to use @time
correctly have been discussed.
add a comment |
Generally, it is recommended to use BenchmarkTools.jl for benchmarking a piece of code.
Paralleling the @time
macro in Base
Julia, BenchmarkTools
exports the usually superior @btime
macro, which, among other things, avoids measuring compilation time and performs a more precise statistical analysis. (see the package's documentation for details)
You can use it just as you use the @time
macro, e.g. @btime rand(2,2)
To benchmark a block of code, such as your "main code", you could (and should) put that piece of code into a function or a begin ... end
block. For example,
@btime begin
# my code goes here
end
Note that, independent of benchmarking, it is anyways recommended to put performance critical code into functions, as is explained in the Performance Tips in Julia's documentation.
Having introduced @btime
, of course, if the runtime of your code dominates over compilation time, as should probably be the case when benchmarking the whole code ("main code"), it's often nonetheless fine to use @time
. It should be instructive to read this recent discourse thread where parts of how to use @time
correctly have been discussed.
Generally, it is recommended to use BenchmarkTools.jl for benchmarking a piece of code.
Paralleling the @time
macro in Base
Julia, BenchmarkTools
exports the usually superior @btime
macro, which, among other things, avoids measuring compilation time and performs a more precise statistical analysis. (see the package's documentation for details)
You can use it just as you use the @time
macro, e.g. @btime rand(2,2)
To benchmark a block of code, such as your "main code", you could (and should) put that piece of code into a function or a begin ... end
block. For example,
@btime begin
# my code goes here
end
Note that, independent of benchmarking, it is anyways recommended to put performance critical code into functions, as is explained in the Performance Tips in Julia's documentation.
Having introduced @btime
, of course, if the runtime of your code dominates over compilation time, as should probably be the case when benchmarking the whole code ("main code"), it's often nonetheless fine to use @time
. It should be instructive to read this recent discourse thread where parts of how to use @time
correctly have been discussed.
edited Jan 2 at 9:46
answered Jan 2 at 9:25


crstnbrcrstnbr
4,36811124
4,36811124
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54001682%2fhow-can-i-calculate-time-of-my-main-code%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown