Code Monkey home page Code Monkey logo

Comments (9)

mateogianolio avatar mateogianolio commented on May 12, 2024

Loops through arguments sent to the constructor.

For example:

var a = new Vector(1, 2, 3);

[].slice.call(arguments, 0) is now an array containing [1, 2, 3], which is then iterated over and its values are consequently pushed to the vector. If the argument is an instance of Vector, for example:

var b = new vectorious.Vector(a)

b should now be a copy of a.

I'm considering adding that

var c = new vectorious.Vector(a, b)

would yield a combination of vectors a and b (using Vector.combine). I'm not sure about this yet.

from vectorious.

metabench avatar metabench commented on May 12, 2024

It looks to me that

if(argument instanceof Vector)
          self = argument;

in that loop does not make a copy of the vector, but sets itself to be that vector. Also, if multiple vectors are given, it sets itself to be the last one. Combining vectors looks like a much better idea.

I can speed up the iteration of the arguments by just using a for loop, there is no need to slice an array to get the arguments as an array - we can iterate through the arguments object with no problem.

Also, is there a convenient way to do inline code or code blocks on Github? I'm finding myself copying and pasting that funny quote character.

I'd like us to get some benchmarks set up so as I make optimizations we can track improvements (or differences). I'd like to be able to point to a measurable speed-up with optimizations like this one. I think it would be tiny, but I also think it would be measurable.

from vectorious.

mateogianolio avatar mateogianolio commented on May 12, 2024

Some unexpected issues might arise when using the argument object directly, see this.

I'm glad you pointed this out, an easy fix would be just to replace self = argument with self.combine(argument). This would enable the possibility of calling

var d = new vectorious.Vector(1, 2, 3, b, c)

which would yield [1, 2, 3] combined with b and c.

I agree that setting up benchmarks and unit testing should be our top priorities in order to make this library easier to maintain.

from vectorious.

metabench avatar metabench commented on May 12, 2024

No, there won't be any problems using the arguments object like I described. We won't be doing arguments.shift() or anything else problematic. All we do is use the length property, and get arguments[c], both of which are supported.

from vectorious.

mateogianolio avatar mateogianolio commented on May 12, 2024

Ok, that's great. I will take a fresh look at everything tomorrow and hopefully start coding some of the things we've discussed.

Oh, and on my keyboard (Swedish keyboard layout) I can press Shift + the button next to backspace to get the backtick ("`") character.

from vectorious.

metabench avatar metabench commented on May 12, 2024

I just found out it's been on my UK keyboard in the position just to the left of 1, and I've somehow known of that button's existence but also totally ignored it for many years.

I may do some coding fairly soon. Does me being a collaborator mean I have rights to push to the repo? I'd be pushing optimized code to a new branch, but to begin with I would put in place (in the master branch) a 'benchmarks' directory which I'll use to benchmark the system as it stands, before optimizing and using those same benchmarks to measure the improvements.

from vectorious.

mateogianolio avatar mateogianolio commented on May 12, 2024

Yes, you have pushing privileges.
On Wed 1 Apr 2015 at 18:57 metabench [email protected] wrote:

I just found out it's been on my UK keyboard in the position just to the
left of 1, and I've somehow known of that button's existence but also
totally ignored it for many years.

I may do some coding fairly soon. Does me being a collaborator mean I have
rights to push to the repo? I'd be pushing optimized code to a new branch,
but to begin with I would put in place (in the master branch) a
'benchmarks' directory which I'll use to benchmark the system as it stands,
before optimizing and using those same benchmarks to measure the
improvements.


Reply to this email directly or view it on GitHub
#5 (comment)
.

from vectorious.

metabench avatar metabench commented on May 12, 2024

I've made a new branch called opt-js. I'm using the word / abbreviation 'opt' to mean optimization or optimize, I hope that's OK in various places like the comments and the commit messages.

So far I've found with a benchmark that calls the constructor function many times there has been a speed-up of 3052%. Not a tiny improvement for just calling the constructor function, but that's all my benchmark tests so far. I'll make benchmarks that are representative of other uses of the vector, and optimize the code in other places too.

I'll push benchmarks to both branches, and optimizations to opt-js.

from vectorious.

metabench avatar metabench commented on May 12, 2024

I've just done a benchmarks with 1000 repetitions of adding 4096 pairs of vectors with the improved constructor function. I've got a 369% speedup just from using the improved constructor function.

I'll continue doing some optimizations that don't change the program structure much to start with.

When we are using fixed sized arrays internally, we'll need to handle changing (increasing) the size of the vector. The simpler way is to reallocate and copy when necessary. The more complicated way involves what may be called a linked list of pages.

from vectorious.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.