Fork me on GitHub

"If you already know what recursion is, just remember the answer. Otherwise, find someone who is standing closer to Douglas Hofstadter than you are; then ask him or her what recursion is."


Hello all, is there any way having a number and verify some issues and stop flow if having problems, like in -> ? -> stock, verify with quantity of sales order, descrease stock, add quantity to sales order, if there is no stock, stop the main stream to be processed?


in clojure?


itΒ΄s a pain doing this with many ifs


some-> ... then if any part returns nil the whole pipeline stops.


This one has been in the back of my mind for quite a while... How does one test code dealing with timeouts quickly? Mock timers/clocks that tick faster or is there something better?


100ms is an eternity to the CPU


Precisely my doubt


Any pointers on how to debug a slow performing function?


The code works, but takes about a second to solve for the 7 element vector, which is very poor compared to a similar solution in Java.


The code above runs in less than a millisecond for me for the 7-element vector.


@UC2B7D28Y are you perhaps including jvm/clj startup time in that one-second figure?


@U077BEWNQ I am timing it using the (time) method just before calling the minimumSwaps() .. I need to figure out how 'time' calcs its elapsed time


Shouldn't be including startup time, then. I suspect something's weird with your setup, mfikes' time seems much more what I would expect.


So, I was able to marginally optimize it, by using 'drop' (which returns a lazy sequence) over 'subvec' (returns a persistent vector).. I should maybe check my setup too.


My recommendation is to not even think about optimizing the code until you solve the setup problems. I just ran it in the REPL I happened to have open, & similar results to Mike:

user> (time (println (minimumSwaps [7 6 5 4 3 2 1])))
"Elapsed time: 1.254905 msecs"


This isn't an issue with unoptimized code unless you're running on a box that's more than 15 years old πŸ˜‰


Maybe tell us how exactly you're loading and running it? Is this in a command-line clojure REPL? Or in some editor? Give us the details of your setup πŸ™‚


(also feel free to move it back to the main #beginners thread if you'd prefer; if nothing else, you might get faster responses)


Thanks for the quick response @U077BEWNQ.. I am uploading my answers to HackerRank and the inputs on hacker rank have vector sizes of 100K & upwards. My performance problems are for larger data sets.


My IDE is spacemacs and I am using CIDER REPL...


I also ran it in Spacemacs/CIDER. Something's definitely not right with your setup.


OK, @U077BEWNQ ill check out a few things on my end


@U077BEWNQ Ill move my question to the beginner thread. I implemented a similar solution in java and it performs better than the clojure code.. I wonder how I can optimize my coljure solution..


If it were me, I'd probably start by calling htop or top. I wonder if you've somehow got a bunch of orphaned JVM processes out there. I'd follow that with an emacs restart, and if that didn't work, a system reboot. Those three between them should identify or rule out the most likely problems. That said, I definitely hear that your broader question is about how to optimize the code, not about why it takes a full second to run, so I'll leave it at that.


@U077BEWNQ - Thanks for the tips, trying them out now.


I already tried providing the explicit types, but doesnt seem to make a difference


I tried using transients, but has an open bug for subvec, that I am using in my solution-


@jaihindh.reddy I think tea-time might be helpful?


hello, an editing related question, i've got a sexp (foo (bar a b c) d), now I only want (bar a b c), is there any paredit shortcut or something similar to help me delete outer stuff in one go?


Put point on the opening paren and involve paredit raise sexp


thanks @dpsutton... i was searching words like promote and cannot find anything, raise is the right word for it, πŸ˜„